查询/删除/建立DB2数据表的主键
一、查询表主键。
describe indexes for table <instancename>.<tablename>
例:
describe indexes for table db2inst1.aaa
二、删除表主键。
alter table <instancename>.<tablename> drop primary key
例:
alter table db2inst1.aaa drop primary key
三、建立表主键。
alter table <instancename>.<tablename> add CONSTRAINT <primarykeyname> PRIMARY KEY (<columnname>)
例:
alter table db2inst1.aaa add constraint aaa_pk primary key(id)
--分配结余、备注
ALTER TABLE DMS.PT_MONTHLYCLOSING ADD COLUMN NRALBL DECIMAL(14,2);
ALTER TABLE DMS.PT_MONTHLYCLOSING ADD COLUMN NSDEMO VARCHAR(500);
--2015-05-12
ALTER TABLE DMS.PT_MONTHLYCLOSING ADD COLUMN FLOWNO VARCHAR(50) NOT NULL DEFAULT '0';
UPDATE DMS.PT_MONTHLYCLOSING SET FLOWNO = CHAR(ACCESS_DATE)||'*'||MAINTENANCE_CD||'*'||SORTING;
ALTER TABLE DMS.PT_MONTHLYCLOSING DROP PRIMARY KEY;
ALTER TABLE DMS.PT_MONTHLYCLOSING ADD CONSTRAINT PK_FLOWNO PRIMARY KEY(FLOWNO);