DB2 PrimaryKey 主键操作SQL总结

Categories: Database; Tagged with: ; @ October 5th, 2010 21:06

1. ADD PRIMARY KEY 增加主键

ALTER TABLE EMPLOYEE ADD PRIMARY KEY (EMPLOYEE_ID, ORGNO);

2. DROP PRIMARY KEY 删除主键

ALTER TABLE EMPLOYEE DROP PRIMARY KEY

3. SET AUTOINCREMENT 设置自增

ALTER TABLE TB2 ALTER COLUMN ID (DROP DEFAULT) SET GENERATED AS IDENTITY ( START WITH 0 INCREMENT BY 1 NO CACHE ) ;

DROP DEFATULT: 如果之前已有DEFAULT值时使用.

通过ALERT为DB2 TABLE增加/删除主键 ADD/DROP PRIMARY KEY

Categories: Database; Tagged with: ; @ October 3rd, 2010 15:01

Drop Primary Key 移除主键:

ALTER TABLE TABLE2 DROP PRIMARY KEY

Add Primary Key 增加主键:

ALTER TABLE TABLE2 ADD ID2 INTEGER NOT NULL DEFAULT 1;
ALTER TABLE TABLE2 ADD PRIMARY KEY(ID2);

See: http://bytes.com/topic/db2/answers/670160-how-change-primary-key-already-existing-table

DB2获得表内主键 Get PrimaryKeys

Categories: Database; Tagged with: ; @ October 3rd, 2010 14:50

SQL:

SELECT * FROM SYSIBM.SYSCOLUMNS WHERE TBCREATOR NOT LIKE ‘SYS%’ AND TBNAME = ‘TABLENAME‘ AND KEYSEQ > 0 ORDER BY KEYSEQ ASC;

(more…)



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.