Saturday, January 6, 2018

To View Constraints in SQL Server database

quick and dirty:
SELECT * FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'



Clearer:

SELECT OBJECT_NAME(object_id) AS ConstraintName,

SCHEMA_NAME(schema_id) AS SchemaName,

OBJECT_NAME(parent_object_id) AS TableName,

type_desc AS ConstraintType

FROM sys.objects

WHERE type_desc LIKE '%CONSTRAINT'

For specific  table:

add the following to very end:
AND OBJECT_NAME(parent_object_id)= 'theNameOfYourTable'


thanks to: https://bhaveshgpatel.wordpress.com/2009/11/04/sql-server-list-all-constraints-of-database-or-table/

No comments: