1.查询该表的主键被那些表作为外键使用:
SELECT B.TABLE_NAME
FROM ALL_CONSTRAINTS A, ALL_CONSTRAINTS B
WHERE A.TABLE_NAME = ‘表名‘
AND A.OWNER = SYS_CONTEXT(‘USERENV‘, ‘CURRENT_SCHEMA‘)
AND B.OWNER = SYS_CONTEXT(‘USERENV‘, ‘CURRENT_SCHEMA‘)
AND B.CONSTRAINT_TYPE = ‘R‘
AND A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME;
2.查询该表引用了那些表的主键作为外键:
SELECT A.TABLE_NAME
FROM USER_CONS_COLUMNS A
LEFT JOIN ALL_CONSTRAINTS B
ON A.CONSTRAINT_NAME = B.R_CONSTRAINT_NAME
WHERE B.CONSTRAINT_TYPE = ‘R‘
AND B.TABLE_NAME = ‘表名‘;
替换其中的‘表名’即可。
原文地址:http://blog.51cto.com/13003060/2339072
时间: 2024-10-15 13:55:42