Get all Default Constraints for a table in SQL Server

The below snippet will list all check constraints for a given table in SQL Server:


SELECT
	DC.Name
FROM
	sys.schemas S
	INNER JOIN Sys.objects O
		on S.schema_id = O.schema_id
	INNER JOIN Sys.default_constraints DC
		ON O.object_id = dc.parent_object_id
WHERE
	S.name = 'SCHEMA_NAME'
AND
	O.name = 'TABLE_NAME'

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s