MySQL:如何找出哪些表引用了特定表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/754512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL: How do I find out which tables reference a specific table?
提问by
I want to drop a table but it is referenced by one or more other tables. How can I find out which tables are referencing this table without having to look at each of the tables in the database one by one?
我想删除一张表,但它被一个或多个其他表引用。如何找出哪些表引用了这个表,而不必一一查看数据库中的每个表?
回答by
select table_name
from information_schema.KEY_COLUMN_USAGE
where table_schema = 'my_database'
and referenced_table_name = 'my_table_here';
This works.
这有效。
回答by Michael Buen
select table_name
from information_schema.referential_constraints
where referenced_table_name = 'parent table here';
回答by Eugene Yarmash
If you have phpMyAdmininstalled, you can use its designer featureto visualize table relationships.
如果您安装了phpMyAdmin,您可以使用其设计器功能来可视化表关系。
To use the designer, select a database, then look for the Designertab.
要使用设计器,请选择一个数据库,然后查找“设计器”选项卡。
回答by Srikar Doddi
Use Toad to load it up and you can view the references through the diagram. also make sure that you don't have any app code passing sql from the front-end, dropping the table may cause the app to break.
使用 Toad 加载它,您可以通过图表查看参考。还要确保您没有任何应用程序代码从前端传递 sql,删除表可能会导致应用程序中断。
Download link http://www.toadsoft.com/toadmysql/FreewareDownload.htm
下载链接 http://www.toadsoft.com/toadmysql/FreewareDownload.htm
If you are using innoDB try this one SHOW TABLE STATUS FROM yourdatabasename LIKE 'T' http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
如果你正在使用 innoDB,试试这个 SHOW TABLE STATUS FROM yourdatabasename LIKE 'T' http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
回答by Milhous
Look at the KEY_COLUMN_USAGE table in the iformation_schema schema.
查看 iformation_schema 模式中的 KEY_COLUMN_USAGE 表。
回答by Will Glass
from the mysql command line: show table status
从 mysql 命令行:显示表状态
回答by user7209199
you could try MySql workbench which allows you to extract E.R. diagram. In this you can find all you need about tables of your database.
您可以尝试 MySql 工作台,它允许您提取 ER 图。在这里,您可以找到有关数据库表的所有信息。