Skip to content

Latest commit

 

History

History
88 lines (62 loc) · 3.15 KB

File metadata and controls

88 lines (62 loc) · 3.15 KB
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
ignite-2025
f1_keywords
sp_helpconstraint
sp_helpconstraint_TSQL
helpviewer_keywords
sp_helpconstraint
dev_langs
TSQL
monikerRange =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb

sp_helpconstraint (Transact-SQL)

[!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

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

EXECUTE sp_helpconstraint 'Production.Product';

Related content