TSQL alter table add new column – constraint

March 2, 2011

(1) Comment

This is very basic sample for adding new column to a existing table and set default value by adding constraints.
You can do this via SQL Server Management Studio but this is TSQL example!

/*
This script will add new field IsManager to table Employee
and set default value to 0.
After creation of the field, run update statement to populate
IsManager =0 for existing record.
*/

Go
Alter Table tbl_Employee add [IsManager] [bit] NULL

Go
ALTER TABLE tbl_Employee ADD  CONSTRAINT [DF_Employee_IsManager]  DEFAULT ((0)) FOR [IsManager]

Go
UPDATE Employee
SET [IsManager]=0

One response to "TSQL alter table add new column – constraint"

SAM said:
March 12, 2011

really useful

Leave a comment

Name : 
Mail : 
Website : 
Message :