Add-DefaultConstraint

Creates a Default constraint to an existing column

Syntax

Add-DefaultConstraint [-TableName] <String> [-SchemaName <String>] [-ColumnName] <String> [-Name <String>] [-Expression] <String> [-WithValues] [<CommonParameters>]

Description

The DEFAULT constraint is used to insert a default value into a column. The default value will be added to all new records, if no other value is specified.

Related Commands

Parameters

Name Type Description Required? Pipeline Input Default Value
TableName String

The name of the target table.

true false
SchemaName String

The schema name of the target table. Defaults to dbo.

false false dbo
ColumnName String

The column on which to add the default constraint

true false
Name String

The name for the . If not given, a sensible name will be created.

false false
Expression String

The default expression

true false
WithValues SwitchParameter

WithValues

false false False

EXAMPLE 1

Add-DefaultConstraint -TableName Cars -ColumnName Year -Expression '2015'

Adds an Default constraint on column 'Year' in the table 'Cars'