简体   繁体   English

MySQL-如何列出所有具有外键的表,这些外键都指向表的主键?

[英]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_nametable_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.

相关问题 引用同一张表中的主键的外键 - Foreign key referring to primary key in the same table Mysql 如何在外键指向其他表主键的JOIN 2表中返回SQL中具有该主键的所有行? - How to to JOIN 2 tables with foreign key pointing to other table primary key to return all the row that have such primary key in SQL? MySQL插入外键引用主ID - Mysql insert with foreign key referring to primary id 相同的外键列引用2个表的2个独立主键 - Same Foreign key column referring to 2 separate primary key of 2 table 没有主键而是外键的MySQL表 - Mysql table with no primary key but a foreign key 如何从另一个表主键添加mysql外键? - How to Add mysql foreign key from another table primary key? 我的桌子上的主键和外键 - PRIMARY KEY and FOREIGN KEY to my table 如何从同一个表中的主键和外键mysql表中删除主键。 - How to remove primary key from a mysql table which is primary key and foreign key in the same table as well.? 我遇到了有关数据库表中应包含主键和外键的挑战 - i have a challenge relating what should be primary key and foreign key in my database tables MySQL中如何将主表的Primary Key值插入到子表的Foreign Key列? - How to insert Primary Key value of the primary table to the Foreign Key column of the child table in MySQL?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM