Technical Article

Find Constraints on a table

,

This script would help find primary key, foriegn key, unique constraints, check constraints on a table. With slight modification you can use it to find various information about a table.

select b.COLUMN_NAME
from INFORMATION_SCHEMA.table_constraints a
inner join INFORMATION_SCHEMA.key_column_usage b on
a.CONSTRAINT_CATALOG = b.CONSTRAINT_CATALOG and
a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME
wherea.TABLE_CATALOG = '<db Name>'
anda.TABLE_SCHEMA = '<owner Name'
anda.TABLE_NAME = '<table Name>'
anda.CONSTRAINT_TYPE = '<constraint Type>'
order by b.ordinal_position

Read 522 times
(8 in last 30 days)

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating