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
  1. really useful

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>