Created
August 9, 2013 09:48
-
-
Save breenie/6192497 to your computer and use it in GitHub Desktop.
Find directly dependant MYSQL tables... Lifted from http://oakgreen.blogspot.in/2011/05/mysql-query-to-get-all-child-tables-for.html
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 c.table_schema,u.table_name,u.column_name,u.referenced_table_name,u.referenced_column_name | |
FROM information_schema.table_constraints AS c | |
INNER JOIN information_schema.key_column_usage AS u | |
USING( constraint_schema, constraint_name ) | |
WHERE c.constraint_type = 'FOREIGN KEY' | |
AND u.referenced_table_schema='<database>' | |
AND u.referenced_table_name = '<table>' | |
ORDER BY c.table_schema,u.table_name; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment