Bala's Development Blog

.Net,SQL Server, ASP.Net ……

TSQL alter table add new column – constraint

with one 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

Written by BALA SINGAM

March 2nd, 2011 at 12:21 am

One Response to 'TSQL alter table add new column – constraint'

Subscribe to comments with RSS or TrackBack to 'TSQL alter table add new column – constraint'.

  1. really useful

    SAM

    12 Mar 11 at 1:54 pm

Leave a Reply