[英]MySQL - How to list all tables that have a foreign key referring to my table's primary key?
在一个MYSQL数据库中,我想找出当前数据库中所有以我选择的表的主键作为其外键的表,换句话说,它们是在引用我的表。
You can just do something like this: 您可以执行以下操作:
USE information_schema;
SELECT *
FROM
key_column_usage
WHERE
REFERENCED_TABLE_NAME = 'table_name'
AND REFERENCED_COLUMN_NAME = 'table_id'
AND TABLE_SCHEMA = 'your_database_name';
Replace the table_name
and table_id
with the your table name and column name. 将table_name
和table_id
替换为您的表名和列名。
I guess the last answer was almost correct. 我猜最后一个答案几乎是正确的。 just change the table from "key_column" to "key_column_usage. 只需将表从“ key_column”更改为“ key_column_usage”即可。
Cheers 干杯
Nikao 尼高
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.