devxlogo

Set a Column’s Default Value As Part of the Create Table

Set a Column’s Default Value As Part of the Create Table

In SQL Server, a column’s default value can be specified as part of the Create Table statement. This default value will be set for the specified column in cases where an insert is performed but this column’s value is not set. The given example sets this default as ‘MyDefaultValue’ for name column.

Example:

  Create Table MyTable(id int not null,name char(50) default  'MyDefaultValue')

devx-admin

Share the Post: