Summarize All the Constraints for a Table

The sp_showConstraints stored procedure is an alternative to using sp_helpconstraint when you need to find all the constraints for a table.

Eli Leiba

October 25, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


The output of the sp_helpconstraint system stored procedure consists of three result sets, so you can't insert the output into a temporary table.Therefore, I created the sp_showConstraints stored procedure as a short and simple alternative to using sp_helpconstraint when I need to find all the constraints for a table.

The sp_showConstraints store procedure analyzes all constraints and summarizes them in a short result set that consists of the constraint name, ID, type, and level. All information is decoded out of the sysconstraints system table.

Listing 1 shows the code for sp_show-Constraints. To use this stored procedure, you call it with code such as

USE pubs GO EXEC sp_showConstraints 'Authors' 

Table 1 shows sample results from sp_showConstraints. I tested this procedure in SQL Server 2005.
— Eli Leiba

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like