DB2数据库ALTER命令(修改表结构相关)

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;

--以上为个人平时整理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wyalbert

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值