Created
September 21, 2021 05:09
-
-
Save mystikraz/ee15cf81ad04cb122abc99f034b83342 to your computer and use it in GitHub Desktop.
list all references of a table in Mysql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| ku.CONSTRAINT_NAME AS "Foreign key", | |
| -- CONCAT("`", ku.TABLE_SCHEMA, "`.`", ku.TABLE_NAME, "`") AS "In", | |
| ku.TABLE_NAME AS "In", | |
| GROUP_CONCAT(ku.COLUMN_NAME) AS "Source column", | |
| CONCAT("`", ku.REFERENCED_TABLE_SCHEMA, "`.`", ku.REFERENCED_TABLE_NAME, "`") AS "References", | |
| GROUP_CONCAT(ku.REFERENCED_COLUMN_NAME) AS "Target column" | |
| FROM information_schema.KEY_COLUMN_USAGE AS ku | |
| WHERE ku.REFERENCED_TABLE_SCHEMA = 'dev.bidenergy.com' | |
| AND ku.REFERENCED_TABLE_NAME = 'site' | |
| GROUP BY ku.CONSTRAINT_NAME | |
| HAVING `In` != `References` | |
| select table_name | |
| from information_schema.KEY_COLUMN_USAGE | |
| where table_schema = 'dev.bidenergy.com' | |
| and referenced_table_name = 'site'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment