Skip to content

Latest commit

 

History

History
84 lines (60 loc) · 3.07 KB

sp-helpconstraint-transact-sql.md

File metadata and controls

84 lines (60 loc) · 3.07 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
sp_helpconstraint (Transact-SQL)
sp_helpconstraint returns a list of all constraint types and their information.
markingmyname
maghan
randolphwest
05/14/2024
sql
system-objects
reference
sp_helpconstraint
sp_helpconstraint_TSQL
sp_helpconstraint
TSQL
=azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current

sp_helpconstraint (Transact-SQL)

[!INCLUDE SQL Server SQL MI]

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

Syntax

sp_helpconstraint
    [ @objname = ] N'objname'
    [ , [ @nomsg = ] 'nomsg' ]
[ ; ]

Arguments

[ @objname = ] N'objname'

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.

[ @nomsg = ] 'nomsg'

An optional parameter that prints the table name. @nomsg is varchar(5), with a default of msg. nomsg suppresses the printing.

Return code values

0 (success) or 1 (failure).

Result set

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.

Remarks

Executing sp_help <table> reports all information about the specified table. To see only the constraint information, use sp_helpconstraint.

Permissions

Requires membership in the public role.

Examples

[!INCLUDE article-uses-adventureworks]

The following example shows all constraints for the Product.Product table.

USE AdventureWorks2022;
GO
EXEC sp_helpconstraint 'Production.Product';

Related content