[英]SQL Return list of tables containing foreign keys related to a primary key
I am trying to query the mySQL database to return a list of tables containing a foreign key associated with a primary key. 我正在尝试查询mySQL数据库以返回包含与主键关联的外键的表的列表。 For example, I have a table containing "reference_number" and other tables containing "reference_number" as a foreign key. 例如,我有一个包含“reference_number”的表和包含“reference_number”作为外键的其他表。 How would I query the database to return the list of tables containing "reference_number" as a foreign key? 我将如何查询数据库以返回包含“ reference_number”作为外键的表的列表? Thanks. 谢谢。
Possible duplicate: 可能重复:
MySQL: How to I find all tables that have foreign keys that reference particular table.column AND have values for those foreign keys? MySQL:如何查找所有具有引用特定table.column的外键并具有这些外键值的表?
A possible solution is: 可能的解决方案是:
USE information_schema;
SELECT *
FROM
KEY_COLUMN_USAGE
WHERE
REFERENCED_TABLE_NAME = 'your_table'
AND REFERENCED_COLUMN_NAME = 'reference_number';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.