Skip to content

Instantly share code, notes, and snippets.

@breenie
Created August 9, 2013 09:48
Show Gist options
  • Save breenie/6192497 to your computer and use it in GitHub Desktop.
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
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