Saturday, August 30, 2014

How to Add Default Constraints in SQL

Syntax:

create table [Table_Name] (
[Column_Name] [dataType] constraint [Constraint_Name]
Default [Default_Value]
)

The Following example show how to add constraints during table creation process

create table MyTable(
id int not null constraint ConstID
Default 1,
name nvarchar(20)
)

The Following example show how to add constraints after the table has been created

alter table MyTable
add constraint MyConst
Default 'Default Value' for name

I hope it was informative for you and I would like to Thank you for reading

No comments:

Post a Comment