外键列表及其引用的表我正在尝试查找一个查询,它将返回一个表的外键列表以及它们引用的表和列。我在那里一半SELECT a.table_name,
a.column_name,
a.constraint_name,
c.ownerFROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS C
where A.CONSTRAINT_NAME = C.CONSTRAINT_NAME
and a.table_name=:TableName
and C.CONSTRAINT_TYPE = 'R'但我仍然需要知道此键引用了哪个表和主键。我怎么会这样?
3 回答
一只斗牛犬
TA贡献1784条经验 获得超2个赞
引用的主键在列r_owner和r_constraint_name表中描述ALL_CONSTRAINTS。这将为您提供所需的信息:
SELECT a.table_name, a.column_name, a.constraint_name, c.owner,
-- referenced pk
c.r_owner, c_pk.table_name r_table_name, c_pk.constraint_name r_pk
FROM all_cons_columns a
JOIN all_constraints c ON a.owner = c.owner
AND a.constraint_name = c.constraint_name
JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
AND c.r_constraint_name = c_pk.constraint_name
WHERE c.constraint_type = 'R'
AND a.table_name = :TableName
烙印99
TA贡献1829条经验 获得超13个赞
试试这个:
select * from all_constraints where r_constraint_name in (select constraint_name from all_constraints where table_name='YOUR_TABLE_NAME');
- 3 回答
- 0 关注
- 745 浏览
添加回答
举报
0/150
提交
取消