sql - How to find list of tables that are having foreign key contraint for primary key of Table-A? -
how can find out list of various tables having foreign key constraint primary key of particular table.
kindly guide...
here's query using information_schema
, adapted this blog post:
select fk_table = fk.table_name , fk_column = cu.column_name , pk_table = pk.table_name , pk_column = pt.column_name , constraint_name = c.constraint_name information_schema.referential_constraints c join information_schema.table_constraints fk on c.constraint_name = fk.constraint_name join information_schema.table_constraints pk on c.unique_constraint_name = pk.constraint_name join information_schema.key_column_usage cu on c.constraint_name = cu.constraint_name join ( select i1.table_name, i2.column_name information_schema.table_constraints i1 join information_schema.key_column_usage i2 on i1.constraint_name = i2.constraint_name i1.constraint_type = 'primary key' ) pt on pt.table_name = pk.table_name pk.table_name = 'primarykeytable'
Comments
Post a Comment