Technical Article

Getting the FK and PK of any database

,

GETTING PK AND FK FOR ALL TABLES IN A GIVEN DATABASE

SELECT a.TABLE_NAME, b.COLUMN_NAME, a.CONSTRAINT_TYPE 
FROM  
INFORMATION_SCHEMA.table_constraints a,
INFORMATION_SCHEMA.key_column_usage b
WHERE a.CONSTRAINT_CATALOG ='<YOUR CATALOG NAME>'  and
a.CONSTRAINT_CATALOG = b.CONSTRAINT_CATALOG and
a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
ORDER BY A.TABLE_NAME

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating