Вы можете использовать
db2 alter table <table_name> alter column <column_name> drop identity
и
db2 alter table <table_name> alter column <column_name> set generated always as identity (start with <max(column_identity_name)>)
-
[email protected]:/home/db2inst1:>db2 "CREATE TABLE TEST (ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1), NAME CHAR(6))"
insert into test (NAME) VALUES ('test1')"
insert into test (NAME) VALUES ('test2')"
insert into test (NAME) VALUES ('test3')"
insert into test (NAME) VALUES ('test4')"
insert into test (NAME) VALUES ('test5')"
insert into test (NAME) VALUES ('test6')"
insert into test (NAME) VALUES ('test7')"
insert into test (ID,NAME) VALUES (4,'test8')"
insert into test (ID,NAME) VALUES (4,'test9')"
insert into test (ID,NAME) VALUES (4,'test10')"
insert into test (ID,NAME) VALUES (4,'test11')"
insert into test (ID,NAME) VALUES (4,'test12')"
insert into test (ID,NAME) VALUES (2,'test13')"
insert into test (ID,NAME) VALUES (2,'test14')"
insert into test (ID,NAME) VALUES (2,'test15')"
insert into test (ID,NAME) VALUES (3,'test16')"
insert into test (NAME) VALUES ('test17')"
insert into test (NAME) VALUES ('test18')"
insert into test (NAME) VALUES ('test19')"
insert into test (NAME) VALUES ('test20')"
insert into test (NAME) VALUES ('test21')"
insert into test (NAME) VALUES ('test22')"
insert into test (NAME) VALUES ('test23')"
insert into test (NAME) VALUES ('test24')"
-
[email protected]:/home/db2inst1:>db2 "select row_number() over (order by ID) as ROWID,ID,NAME from test"
ID NAME
-------------------- -------------------- ------
1 1 test1
2 2 test2
3 2 test13
4 2 test14
5 2 test15
6 3 test3
7 3 test16
8 4 test4
9 4 test8
10 4 test9
11 4 test10
12 4 test11
13 4 test12
14 5 test5
15 6 test6
16 7 test7
17 8 test17
18 9 test18
19 10 test19
20 11 test20
21 12 test21
22 13 test22
23 14 test23
24 15 test24
24 record(s) selected.
[email protected]:/home/db2inst1:>db2 alter table test alter column id drop identity
DB20000I The SQL command completed successfully.
I найдено начальное значение из max row_number;
[email protected]:/home/db2inst1:>db2 "alter table test alter column id set generated always as identity (start with 25)"
DB20000I The SQL command completed successfully.
insert into test (NAME) VALUES ('test25')"
DB20000I The SQL command completed successfully.
[email protected]:/home/db2inst1:>db2 "select row_number() over (order by ID) as ROWID,ID,NAME from test"
ROWID ID NAME
-------------------- -------------------- ------
1 1 test1
2 2 test2
3 2 test13
4 2 test14
5 2 test15
6 3 test3
7 3 test16
8 4 test4
9 4 test8
10 4 test9
11 4 test10
12 4 test11
13 4 test12
14 5 test5
15 6 test6
16 7 test7
17 8 test17
18 9 test18
19 10 test19
20 11 test20
21 12 test21
22 13 test22
23 14 test23
24 15 test24
25 25 test25
25 record(s) selected.
Смотрите, если это помогает: http://stackoverflow.com/a/32969802/1227152 – mustaccio
https: // publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/sqlp/rbafymst79.htm – Esperento57