扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
****************************************************************************** 脚本1:列出当前模式下所有外键的报告表,可以将其spool到某个文件中 ******************************************************************************/ SELECT RPAD(child.TABLE_NAME,25,' ') Child_Tablename, RPAD(cp.COLUMN_NAME,17,' ') Referring_Column, RPAD(parent.TABLE_NAME,25,' ') Parent_Tablename, RPAD(pc.COLUMN_NAME,15,' ') Referred_Column, RPAD(child.CONSTRAINT_NAME,25,' ') Constraint_Name FROM USER_CONSTRAINTS child, USER_CONSTRAINTS parent, USER_CONS_COLUMNS cp, USER_CONS_COLUMNS pc WHERE child.CONSTRAINT_TYPE = 'R' AND child.R_CONSTRAINT_NAME = PARENT.CONSTRAINT_NAME AND child.CONSTRAINT_NAME = cp.CONSTRAINT_NAME AND parent.CONSTRAINT_NAME = pc.CONSTRAINT_NAME AND cp.POSITION = pc.POSITION ORDER BY child.OWNER, child.TABLE_NAME, child.CONSTRAINT_NAME, cp.POSITION; |
****************************************************************************** 脚本2:删除系统自动生成的外键约束条件 ******************************************************************************/ SELECT 'ALTER TABLE ' || TABLE_NAME ||' '|| 'DROP CONSTRAINT ' || CONSTRAINT_NAME || ' ;' FROM USER_CONSTRAINTS WHERE CONSTRAINT_NAME LIKE 'SYS%' AND CONSTRAINT_TYPE = 'R'; |
ALTER TABLE DJ_NSRXX DROP CONSTRAINT SYS_C000231; |
****************************************************************************** 脚本3:重新创建外键 ******************************************************************************/ SELECT 'ALTER TABLE ' || child.TABLE_NAME||' ' || 'ADD CONSTRAINT ' || '外键名称 ' ||' '|| 'FOREIGN KEY ' || '('|| cp.COLUMN_NAME || ')' || ' '|| 'REFERENCES ' || parent.TABLE_NAME ||' '|| '('|| pc.COLUMN_NAME || ')'|| child.DELETE_RULE || ' ;' FROM USER_CONSTRAINTS child, USER_CONSTRAINTS parent, USER_CONS_COLUMNS cp, USER_CONS_COLUMNS pc WHERE child.CONSTRAINT_TYPE = 'R' AND child.R_OWNER = PARENT.OWNER AND child.R_CONSTRAINT_NAME = PARENT.CONSTRAINT_NAME AND child.CONSTRAINT_NAME = cp.CONSTRAINT_NAME AND parent.CONSTRAINT_NAME = pc.CONSTRAINT_NAME AND cp.POSITION = pc.POSITION AND child.CONSTRAINT_NAME LIKE 'SYS%' ORDER BY child.OWNER, child.TABLE_NAME, child.CONSTRAINT_NAME, cp.POSITION; |
ALTER TABLE DJ_NSRXX ADD CONSTRAINT FK_DJ_NSRXX_DM_GY_SWRY FOREIGN KEY (RYDM) REFERENCES DM_GY_SWRY(RYDM); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。