Bala's Development Blog

TSQL alter table add new column – constraint


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.

Alter Table tbl_Employee add [IsManager] [bit] NULL

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

UPDATE Employee
SET [IsManager]=0

One Response to TSQL alter table add new column – constraint

  1. really useful

Leave a Reply

Your email address will not be published. Required fields are marked *