oracle的增删改表字段
简单示例
1、添加字段:
alter table 表名 add (xxx varchar2(48)/integer, xxx varchar2(48)/integer);
alter table 表名 add (xxx varchar2(48)/integer default’2’);
2、修改字段类型:
– 要修改的列必须为空才能更改数据类型
alter table 表名 modify (xxx varchar(48));
3、修改字段名
alter table 表名 rename column xxx to xxx;
4、删除字段:
alter table 表名 drop column xxx;
5、添加字段备注:
comment on column 表名.字段名 is '输入的备注'
comment on column 库名.表名.字段名 is '输入的备注'
5、添加表备注:
COMMENT ON TABLE 表名 is '输入的备注';
测试数据:
create table Temp(
id1 int,
name2 varchar2(48),
id3 int,
name3 varchar2(48)
);
insert into Temp (id1,Name2,id3,Name3) values(1,'a',2,'b');
insert into Temp (id1,Name2,id3,Name3) values(2,'a',3,'b');
insert into Temp (id1,Name2,id3,Name3) values(3,'a',4,'b');
Oracle表字段的增加、删除、修改和重命名
增加字段语法:alter table tablename add (column 数据类型 default value not null);
说明:alter table 表名 add (字段名 字段类型 默认值 是否为空);
例:alter table sf_users add (HeadPIC blob);
例:alter table sf_users add (userName varchar2(30) default '空' not null);
修改字段类型: alter table tablename modify (column 数据类型 default value not null);
说明:alter table 表名 modify (字段名 字段类型 default 默认值 是否为空);
alter table Temp modify (id5 varchar(48));
删除字段:alter table 表名 drop 字段名;
说明:alter table 表名 drop column 字段名;
alter table Temp drop column id3;
字段的重命名: alter table 表名 rename column 列名 to 新列名
alter table Temp rename column id3 to id5;
表的重命名 alter table 表名 rename to 新表名
alter table Temp rename to TempNew;
alter table TempNew rename to Temp;