List Foreign Key Constraints -MS SQL

12 March,2007 by Jack Vamvas

A Foreign Key Constraint is defined when a table is modified or created. A Foreign Key enforces a relationship between data on two tables.
To list Foreign Key Constraints use this SQL code.

select c_c_u.table_name sr_c_table, c_c_u.constraint_name sr_c_constraint, c_c_u.column_name sr_c_col, k_c_u.table_name target_table, k_c_u.column_name target_col
from INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE c_c_u, INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS r_c, INFORMATION_SCHEMA.KEY_COLUMN_USAGE k_c_u where c_c_u.constraint_name = r_c.constraint_name and k_c_u.constraint_name = r_c.unique_constraint_name order by c_c_u.table_name, c_c_u.constraint_name

 Related Posts

JOIN IN SQL FAQ

 SQL server – What is a SQL index key?


Author: Jack Vamvas (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on List Foreign Key Constraints -MS SQL


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer