如何更改现有DB2表中的现有列自动增量?
答案 0 :(得分:1)
如果你创建了一个包含普通列的表格,例如 id 列:
CREATE TABLE demo_tab
(id int NOT NULL PRIMARY KEY,
col_txt VARCHAR(20)
);
但是后来你决定让它像 GENERATED ALWAYS AS IDENTITY 一样:
CREATE TABLE demo_tab
(id int NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) PRIMARY KEY,
col_txt VARCHAR(20)
);
使用此声明:
ALTER TABLE demo_tab ALTER COLUMN id
SET GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1);
并且不要忘记重新组织表格:
CALL SYSPROC.ADMIN_CMD('REORG TABLE demo_tab');
答案 1 :(得分:0)
如果你想修改你的identityvalue,试试这个
ALTER TABLE yourtable ALTER COLUMN youridentitycomunname RESTART WITH yourcountervalue