Db2 alter table name

Source: Internet
Author: User

When you modify a table name in db2, the table cannot have foreign key constraints and cannot be referenced by views ......... -- Example rename table into TCASH_AVMACCOUNT; rename table TPA_BOMACCOUNT TO TCASH_BOMACCOUNT; rename table failed TO continue; rename table TPA_HEADINFO TO TCASH_HEADINFO; -- db2 reported a lot of errors (a little scared at first) before issuing a RENAME statement, delete the View dependent on the table, specify the query table, trigger, SQL function, SQL method, check constraint, reference constraint, or XSR object. For view or specific query tables dependent on this table, query SYSCAT. VIEWDEP and match the table with the BSCHEMA and BNAME columns. For triggers dependent on this table, query SYSCAT. TRIGDEP and match the table with the BSCHEMA and BNAME columns. For SQL functions or SQL methods, query SYSCAT. FUNCDEP and match the table with the BSCHEMA and BNAME columns. For Table check constraints, query SYSCAT. CHECKS and match the table with the TABSCHEMA and TABBNAME columns. For reference constraints dependent on this table, query SYSCAT. REFERENCES and match the table with the TABSCHEMA and TABNAME columns, or the REFTABSCHEMA and REFTABNAME columns. For XSR objects enabled for splitting the table as the target, query SYSCAT. XSROBJECTDEP and match the table with the BSCHEMA and BNAME columns. -- It seems that there are many restrictions. Based on the error prompt, view the object dependency select * from SYSCAT. VIEWDEP where bschema = 'l _ sz_v16' and bname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CSCTICKET ', 'tpa _ headinfo '); select * from SYSCAT. TRIGDEP where bschema = 'l _ sz_v16' and bname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CSCTICKET ', 'tpa _ headinfo '); select * from SYSCAT. FUNCDEP where bschema = 'l _ sz_v16' and bname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CS CTICKET ', 'tpa _ headinfo'); SELECT * from syscat. checks where tabschema = 'l _ sz_v16' and tabname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CSCTICKET ', 'tpa _ headinfo '); SELECT * from syscat. references where tabschema = 'l _ sz_v16' and tabname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CSCTICKET ', 'tpa _ headinfo '); SELECT * from syscat. references where reftabschema = 'l _ SZ_V16 'and reftabname in ('tpa _ AVMACCOUNT', 'T PA_BOMACCOUNT ', 'tpa _ CSCTICKET', 'tpa _ headinfo'); SELECT * from syscat. xsrobjectdep where bschema = 'l _ sz_v16' and bname in ('tpa _ AVMACCOUNT ', 'tpa _ BOMACCOUNT', 'tpa _ CSCTICKET ', 'tpa _ headinfo '); after checking the TABLE, it is found that the TABLE has foreign key constraints, and none of the others -- execute sqlALTER TABLE TPA_AVMACCOUNT drop foreign key FK57641F8FB2FBC862; alter table TPA_CSCTICKET drop foreign key constraint; COMMIT; rename table TPA_AVMACCOUNT TO TCASH_AVMACCOUNT; Rename table TPA_BOMACCOUNT TO TCASH_BOMACCOUNT, then execute. Alter table allow add constraint limit foreign key (Limit) REFERENCES TCASH_BOMACCOUNT (RECORDID) on delete cascade on update restrict enforced enable query optimization; alter table TCASH_AVMACCOUNT add constraint limit foreign key (Limit) REFERENCES TCASH_HEADINFO (RECORDID) on delete cascade on update restrict enforced enable query optimization; COMMIT;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.