您的位置:首页 > 数据库

db2中表的一些常用操作语句。

2017-01-02 22:19 260 查看
1.表中添加字段:
alter table 表名 add column 字段名 字段类型
2.给表中的字段重新命名:
altet table 表名 rename column 原字段名 to 现字段名; 
3.修改表名:
rename table  旧表名  to 新的表名;
4.添加联合主键:
alter table 表名 add constraint  联合主键名称   primary key(主键1,主键2);
5.删除表中的主键:
alter table 表名 drop primary;
6.修改表中的字段类型或者长度:
       alter table 表名 alter column 字段名 set data type 字段类型(或字段长度);
7.添加索引
create index 索引名称 on 表名(字段名称);//给表中的某个字段加上索引(索引名称要见名知意,index_XX)
8.重构表

        db2 reorg table 表名;

9.字段加上注释

        comment on column 表名.字段名   is   '注释名'

。。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息