db2字段修改(增,删,改)操作

2022/1/26 19:09:40

本文主要是介绍db2字段修改(增,删,改)操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.添加字段

alter table [table_name] add [column_name] [column_type] add [column_name] [column_type];

 

2.添加字段带默认值

alter table [table_name] add column [column_name] [column_type] not null with default [value];

 

3.删除字段

alter table [table_name] drop column [column_name];

 

4.修改字段类型

alter table  [table_name] alter column [column_name] set data type  [column_type];

 

5.将原表列not null属性修改为null属性

alter table  [table_name] alter column [column_name] drop not null;

以上所有的修改都会将表处于reorg pending状态所以我们必须进行reorg才能使该表恢复到正常状态。否则表不可以使用,查询或更新报错 DB2 sqlstate 57016

 

6.reorg操作

reorg table [table_name] 

如果我们不是DBA的话,好多链接数据库的客户端工具是不能执行 reorg table [table_name] 的,我们可以用下面的语句执行reorg操作:

call SYSPROC.ADMIN_CMD('reorg table [table_name]')

实际上reorg就是调用的SYSPROC.ADMIN_CMD

 



这篇关于db2字段修改(增,删,改)操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程