352262 发表于 2016-11-17 06:53:08

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 SEQUENCESEQ_CCP_CM_CLIENT_INFO START WITH ' || SEQ_CCP_CM_CLIENT_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_MM_BRODCAST_INFO START WITH ' || SEQ_CCP_MM_BRODCAST_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_MM_INDUSTRY_INFO START WITH ' || SEQ_CCP_MM_INDUSTRY_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_MM_WARN_LEVEL START WITH ' || SEQ_CCP_MM_WARN_LEVEL.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_RM_BACK_PLAN START WITH ' || SEQ_CCP_RM_BACK_PLAN.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_RM_CERT_INFO START WITH ' || SEQ_CCP_RM_CERT_INFO.nextval from sysibm.sysdummy1
SELECT 'CREATE SEQUENCESEQ_CCP_RM_CLNT_RELATION START WITH ' || SEQ_CCP_RM_CLNT_RELATION.nextval from sysibm.sysdummy1


3. 执行第二步生成的语句。应该还可行列自动化一点,目前没时间测试!
页: [1]
查看完整版本: DB2数据库移植时,序列的移植方法