Sunday, May 22, 2011

MySql query to get all the child tables for given parent table

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='db'
AND u.referenced_table_name = 'table'
ORDER BY c.table_schema,u.table_name;

No comments:

Post a Comment