mysql表之间的联系怎么看,如何找到所有mysql表之间的所有关系?

How to find all the relations between all MySQL tables? If for example, I want to know the relation of tables in a database of having around 100 tables.

Is that got any ways to know this?

Thank you..

解决方案

The better way, programmatically speaking, is gathering data from INFORMATION_SCHEMA.KEY_COLUMN_USAGE table as follows:

SELECT

`TABLE_SCHEMA`, -- Foreign key schema

`TABLE_NAME`, -- Foreign key table

`COLUMN_NAME`, -- Foreign key column

`REFERENCED_TABLE_SCHEMA`, -- Origin key schema

`REFERENCED_TABLE_NAME`, -- Origin key table

`REFERENCED_COLUMN_NAME` -- Origin key column

FROM

`INFORMATION_SCHEMA`.`KEY_COLUMN_USAGE` -- Will fail if user don't have privilege

WHERE

`TABLE_SCHEMA` = SCHEMA() -- Detect current schema in USE

AND `REFERENCED_TABLE_NAME` IS NOT NULL; -- Only tables with foreign keys

There are more columns info like ORDINAL_POSITION that could be useful depending your purpose.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值