db2 在修改表名的时候,表上不能有外键约束,不能被视图引用。。。。。。。。。
--例子
RENAME TABLETPA_AVMACCOUNTTOTCASH_AVMACCOUNT;
RENAME TABLE TPA_BOMACCOUNT TOTCASH_BOMACCOUNT;
RENAME TABLE TPA_CSCTICKETTOTCASH_CSCTICKET;
RENAME TABLE TPA_HEADINFO TOTCASH_HEADINFO;
--db2 报了一大堆错误(刚开始有点怕怕的)
在发出 RENAME 语句之前,删除依赖于此表的视图、具体化查询表、触发器、SQL
函数、SQL 方法、检查约束、引用约束或 XSR 对象。对于依赖于此表的视图或具
体化查询表,请查询 SYSCAT.VIEWDEP 并使表与 BSCHEMA 和 BNAME 列匹配。对
于依赖于此表的触发器,请查询 SYSCAT.TRIGDEP 并使表与 BSCHEMA 和 BNAME
列匹配。对于 SQL 函数或 SQL 方法,请查询 SYSCAT.FUNCDEP 并使表与 BSCHEMA
和 BNAME 列匹配。对于表的检查约束,请查询 SYSCAT.CHECKS 并使表与
TABSCHEMA 和 TABBNAME 列匹配。对于依赖于此表的引用约束,请查询
SYSCAT.REFERENCES 并使表与 TABSCHEMA 和 TABNAME 列或者 REFTABSCHEMA 和
REFTABNAME 列匹配。对于为了进行将此表作为目标的分解而启用的 XSR 对象,
请查询 SYSCAT.XSROBJECTDEP 并使表与 BSCHEMA 和 BNAME列匹配。
--看来限制条件真多,根据错误提示,查看对象的依赖性
select * from SYSCAT.VIEWDEP where bschema='L_SZ_V16' AND BNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
select * from SYSCAT.TRIGDEP wherebschema='L_SZ_V16' AND BNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
select * from SYSCAT.FUNCDEPwhere bschema='L_SZ_V16' AND BNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
SELECT * FROM SYSCAT.CHECKSWHERE TABSCHEMA='L_SZ_V16' AND TABNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
SELECT * FROM SYSCAT.REFERENCES WHERETABSCHEMA='L_SZ_V16' AND TABNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
SELECT * FROM SYSCAT.REFERENCES WHEREREFTABSCHEMA='L_SZ_V16' AND REFTABNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
SELECT * FROM SYSCAT.XSROBJECTDEP WHEREbschema='L_SZ_V16' AND BNAMEIN('TPA_AVMACCOUNT','TPA_BOMACCOUNT','TPA_CSCTICKET','TPA_HEADINFO');
查看后,发现表上有外键约束,其他的都没有
--执行删除外键的sql
ALTER TABLE TPA_AVMACCOUNT DROP FOREIGN KEYFK57641F8FB2FBC862;ALTERTABLE TPA_CSCTICKET DROP FOREIGN KEY FK3505A84597A0F542;
COMMIT;
RENAME TABLE TPA_AVMACCOUNT TOTCASH_AVMACCOUNT;RENAMETABLE TPA_BOMACCOUNT TOTCASH_BOMACCOUNT;RENAMETABLE TPA_CSCTICKET TOTCASH_CSCTICKET;RENAMETABLE TPA_HEADINFO TOTCASH_HEADINFO;
COMMIT;
--执行创建外键的sql,表名TPA_开头的都修改为 TCASH开头,然后执行。
ALTER TABLE TCASH_CSCTICKET ADD CONSTRAINT FK3505A84597A0F542FOREIGN KEY (BOMACCOUNT_RECORDID) REFERENCESTCASH_BOMACCOUNT(RECORDID) ON DELETE CASCADE ON UPDATE RESTRICTENFORCED ENABLE QUERYOPTIMIZATION;ALTERTABLE TCASH_AVMACCOUNT ADD CONSTRAINT FK57641F8FB2FBC862 FOREIGNKEY (HEADINFO_RECORDID) REFERENCES TCASH_HEADINFO(RECORDID) ONDELETE CASCADE ON UPDATE RESTRICT ENFORCED ENABLEQUERYOPTIMIZATION;COMMIT;