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
where	a.TABLE_CATALOG = '<db Name>'
and	a.TABLE_SCHEMA = '<owner Name'
and	a.TABLE_NAME = '<table Name>'
and	a.CONSTRAINT_TYPE = '<constraint Type>'
order by b.ordinal_position

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating