要查询外键所在的表,可以使用以下SQL查询语句:
SELECT
UC.CONSTRAINT_NAME AS FOREIGN_KEY_NAME,
UC.TABLE_NAME AS CHILD_TABLE,
UCC.COLUMN_NAME AS CHILD_COLUMN,
UR.TABLE_NAME AS PARENT_TABLE,
UCR.COLUMN_NAME AS PARENT_COLUMN
FROM
USER_CONSTRAINTS UC
JOIN
USER_CONS_COLUMNS UCC ON UC.CONSTRAINT_NAME = UCC.CONSTRAINT_NAME
JOIN
USER_CONSTRAINTS UR ON UC.R_CONSTRAINT_NAME = UR.CONSTRAINT_NAME
JOIN
USER_CONS_COLUMNS UCR ON UR.CONSTRAINT_NAME = UCR.CONSTRAINT_NAME
WHERE
UC.CONSTRAINT_TYPE = 'R'
AND UC.TABLE_NAME = 'YOUR_TABLE_NAME';
在这个查询中,将会列出指定表中的外键约束的名称,子表名,子表外键列名,父表名和父表外键列名。您可以将’YOUR_TABLE_NAME’替换为您想要查询外键的表名。