Follow sqlserver-dba.com

Subscribe to RSS feed  Follow @jackvamvas - Twitter

*Use the Comments section for questions

SQLServer-DBA.com Links

Dba_db2_button

dba-ninja.com

SQL Server DBA Jobs

How to list constraints of a table

11 January,2016 by Tom Collins

To list SQL Server  table constraints you’ll need to use the INFORMATION_SCHEMA.TABLE_CONSTRAINTS catalogs view. Avoid using the sysobjects view , which is now deprecated.  

The query will return the CONSTRAINT_NAME & CONSTRAINT_TYPE

 

SELECT CONSTRAINT_NAME, CONSTRAINT_TYPE
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE TABLE_SCHEMA = 'MY_SCHEMA' AND TABLE_NAME='MY_TABLE';

 Read More on SQL Server table Constraints

Script to DROP CONSTRAINT and ADD CONSTRAINT for all CHECK CONSTRAINTS

Difference between UNIQUE CONSTRAINT versus UNIQUE INDEX

Modify a SQL CHECK CONSTRAINT - SQL Server

List Foreign Keys referencing tables in SQL Server


Author: Tom Collins (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 How to list constraints of a table


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