需要修改结构的,就用到alter语句,方法如下: alter table语句用于修改已经存在的表的设计。 语法:alter table table add column field type[(size)] [not null] [constraint index] alter table table add constraint multifieldindex alter table table
需要修改结构的,就用到alter语句,方法如下:
alter table语句用于修改已经存在的表的设计。
语法:alter table table add column field type[(size)] [not null] [constraint index]
alter table table add constraint multifieldindex
alter table table drop column field
alter table table drop constraint indexname
说明:table参数用于指定要修改的表的名称。
add column为sql的保留字,使用它将向表中添加字段。
add constraint为sql的保留字,使用它将向表中添加索引。
drop column为sql的保留字,使用它将向表中删除字段。
drop constraint为sql的保留字,使用它将向表中删除索引。
field指定要添加或删除的字段的名称。
type参数指定新建字段的数据类型。
size参数用于指定文本或二进制字段的长度。
indexname参数指定要删除的多重字段索引的名称。
用sql*plus或第三方可以运行sql语句的程序登录数据库:
alter table (表名) add (列名 数据类型);
alter table (表名) modify (列名 数据类型);
alter table (表名) rename column (当前列名) to (新列名);
alter table (表名) drop column (列名);
alter table (当前表名) rename to (新表名);
如:
alter table employ add (weight number(38,0)) ;
alter table employ modify (weight number(13,2)) ;
alter table emp rename cloumn weight to weight_new ;
alter table emp drop column weight_new ;
alter table bouns rename to bonus_new;
增加一个列:
alter table 表名 add(列名 数据类型);
如:
alter table emp add(weight number(38,0));
修改一个列的数据类型(一般限于修改长度,修改为一个不同类型时有诸多限制):
alter table 表名 modify(列名 数据类型);
如:
alter table emp modify(weight number(3,0) not null);
给列改名:
alter table 表名 rename column 当前列名 to 新列名;
如:
alter table emp rename column weight to weight_new;
删除一个列:
alter table 表名 drop column 列名;
如:
alter table emp drop column weight_new;
将一个表改名:
alter table 当前表名 rename to 新表名;
如:
alter table bouns rename to bonus_new