Naveen's Weblog

Bridge to future

List tables linked to a parent table

Posted by codingsense on December 23, 2008

Many times we require to know which child tables are related to the parent table. The following query gives us the tables are related to the parent table with foreign keys.


select TABLE_NAME from INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE WHERE CONSTRAINT_NAME IN(
SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE UNIQUE_CONSTRAINT_NAME IN (
select CONSTRAINT_NAME from INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE where table_name ='ParentTableName'))

Just replace the string ParentTableName with the table name for which you want to search the related child tables.

Happy Learning ;)

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>