How to find all the relations between all mysql tables?

前端 未结 9 1939
甜味超标
甜味超标 2020-12-01 01:12

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 there any

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 01:40

    Try

    SELECT
    `TABLE_NAME`,
    `COLUMN_NAME`,
    `REFERENCED_TABLE_NAME`,
    `REFERENCED_COLUMN_NAME`
    FROM `information_schema`.`KEY_COLUMN_USAGE`
    WHERE `CONSTRAINT_SCHEMA` = 'YOUR_DATABASE_NAME' AND
    `REFERENCED_TABLE_SCHEMA` IS NOT NULL AND
    `REFERENCED_TABLE_NAME` IS NOT NULL AND
    `REFERENCED_COLUMN_NAME` IS NOT NULL

    do not forget to replace YOUR_DATABASE_NAME with your database name!

提交回复
热议问题