| title | sp_helpconstraint (Transact-SQL) | ||
|---|---|---|---|
| description | sp_helpconstraint returns a list of all constraint types and their information. | ||
| author | markingmyname | ||
| ms.author | maghan | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | system-objects | ||
| ms.topic | reference | ||
| ms.custom |
|
||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
||
| monikerRange | =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE SQL Server SQLDB SQLMI FabricSQLDB]
Returns a list of all constraint types, their user-defined or system-supplied name, the columns on which they're defined, and the expression that defines the constraint (for DEFAULT and CHECK constraints only).
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions
sp_helpconstraint
[ @objname = ] N'objname'
[ , [ @nomsg = ] 'nomsg' ]
[ ; ]
Specifies the table for which the constraint information is returned. @objname is nvarchar(776), with no default. The table specified must be local to the current database.
An optional parameter that prints the table name. @nomsg is varchar(5), with a default of msg. nomsg suppresses the printing.
0 (success) or 1 (failure).
sp_helpconstraint displays a descending indexed column if it participated in primary keys. The descending indexed column is listed in the result set with a minus sign (-) following its name. The default, an ascending indexed column, is listed by its name alone.
Executing sp_help <table> reports all information about the specified table. To see only the constraint information, use sp_helpconstraint.
Requires membership in the public role.
[!INCLUDE article-uses-adventureworks]
The following example shows all constraints for the Product.Product table.
USE AdventureWorks2022;
GO
EXECUTE sp_helpconstraint 'Production.Product';