1.修改表中某列(字段)的名称
alter table schema.tableName rename column columnName1 to columnName2
2.修改字段类型
alter table schema.tableName alter column columnName set data type 字段类型 (如vachar(20))
3.添加字段
alter table schema.tableName add column columnName 字段类型
4.删除主键约束
alter table schema tableName drop constraint 主键约束名称
5.添加主键约束
alter table schema tableName add constraint 主键约束名称 primary key (columnName1...)
6.删除字段默认值
alter table schema.tableName alter column columnName drop default
7.添加字段默认值
alter table schema.tableName alter column columnName set default 具体值 (如1,current date)
8.删除非空约束
alter table schema.tableName alter column columnName drop not null
9.添加非空约束
alter table schema.tableName alter column columnName set not null
附:修改表名称的方法
rename schema.tableName1 to schema.tableName2
注:
db2做过alter以后最好都reorg以下,否则总是容易导致表处于挂起状态而无法进行其--他操作。
reorg table tableName;
--以上为个人平时整理