Created
July 12, 2017 14:45
-
-
Save favrik/a78b666b1c063e3ba84e02a287ef27a6 to your computer and use it in GitHub Desktop.
This file contains 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 | |
`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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment