DB2数据库移植时,序列的移植方法

1. 生成以下语句,得到源数据库序列的当前值:

SELECT
    'SELECT ''CREATE SEQUENCE  ' || seqname || ' START WITH '' || ' || seqname ||
    '.nextval from sysibm.sysdummy1'
FROM
    syscat.sequences
WHERE
    seqtype='S'
AND seqschema=CURRENT schema


2. 根据第一步生成的语句,逐句执行产生建立目的数据库序列的SQL语句,如:
SELECT 'CREATE SEQUENCE  SEQ_CCP_CM_CLIENT_INFO START WITH ' || SEQ_CCP_CM_CLIENT_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_MM_BRODCAST_INFO START WITH ' || SEQ_CCP_MM_BRODCAST_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_MM_INDUSTRY_INFO START WITH ' || SEQ_CCP_MM_INDUSTRY_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_MM_WARN_LEVEL START WITH ' || SEQ_CCP_MM_WARN_LEVEL.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_RM_BACK_PLAN START WITH ' || SEQ_CCP_RM_BACK_PLAN.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_RM_CERT_INFO START WITH ' || SEQ_CCP_RM_CERT_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCE  SEQ_CCP_RM_CLNT_RELATION START WITH ' || SEQ_CCP_RM_CLNT_RELATION.nextval from sysibm.sysdummy1


3. 执行第二步生成的语句。应该还可行列自动化一点,目前没时间测试!

你可能感兴趣的:(sql,db2,sequence)