DB2 sequence 迁移
如下脚本,可以将某个用户的全部sequence查询出来,并拼成创建语句。
代码如下:
select 'CREATE OR REPLACE SEQUENCE ' ||SEQNAME||
' AS INT '||
( case when LASTASSIGNEDVAL IS NULL then ' START WITH '||CHAR(BIGINT(START)+1) else ' START WITH '||CHAR(BIGINT(LASTASSIGNEDVAL)+1) end)||
' INCREMENT BY ' ||INCREMENT||
' MINVALUE ' ||MINVALUE||
' MAXVALUE ' ||MAXVALUE||
' ORDER '|| ';'
from SYSIBM.SYSSEQUENCES where OWNER= 'DAGGER'
注意:其中的DAGGER,是需要导出sequence的用户,貌似必须大写的说!并且使用该脚本的用户需要有访问SYSIBM.SYSSEQUENCES的权限。
说明:( case when LASTASSIGNEDVAL IS NULL then ' START WITH '||START else ' START WITH '||LASTASSIGNEDVAL end)
LASTASSIGNEDVAL 为null时,start with的取START值,否则取LASTASSIGNEDVAL
导出结果如下:
CREATE OR REPLACE SEQUENCE ETL_SCHE_EVENT_INST_SEQ AS INT START WITH 21000 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 ORDER ;
CREATE OR REPLACE SEQUENCE ETL_SCHE_FILE_INST_SEQ AS INT START WITH 21277 INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 ORDER ;