Add-CheckConstraint

Add a check constraint to a table.

Syntax

Add-CheckConstraint [-TableName] <String> [-SchemaName <String>] [-Name] <String> [-Expression] <String> [-NotForReplication] [-NoCheck] [<CommonParameters>]

Description

Check constraints add validation for data in columns.

Parameters

Name Type Description Required? Pipeline Input Default Value
TableName String

The name of the check constraint's table.

true false
SchemaName String

The schema of the table. Default is dbo.

false false dbo
Name String

The name of the check constraint.

true false
Expression String

The expression to use for the constraint.

true false
NotForReplication SwitchParameter

Don't use the check constraint when inserting, updating, or deleting rows during replication.

false false False
NoCheck SwitchParameter

Specifies that the data in the table is not validated against a newly added CHECK constraint. If not specified, WITH CHECK is assumed for new constraints.

false false False

EXAMPLE 1

0'

Demonstrates how to add a check constraint to a column that requires the value to be greater than 0.

EXAMPLE 2

0' -NoCheck

Demonstrates how to add a check constraint to a column without validating the current contents of the table against this check.