SQL SERVER – Add Column With Default Column Constraint to Table
http://blog.sqlauthority.com/2008/03/19/sql-server-add-column-with-default-column-constraint-to-table/
March 19, 2008 by pinaldave
Just a day ago while working with database Jr. Developer asked me question how to add column along with column constraint. He also wanted to specify the name of the constraint. The newly added column should not allow NULL value. He requested my help as he thought he might have to write many lines to achieve what was requested.
It is very easy to add column and specify default constraint. I have seen many examples where constraint name is not specified, if constraint name is not specified SQL Server will generate unique name for itself. I prefer to specify my constraint name as per my coding standards. You can read my coding standard here : SQL SERVER Database Coding Standards and Guidelines Complete List Download
ALTER TABLE TestTable
ADD NewCol VARCHAR ( 50 )
CONSTRAINT DF_TestTable_NewCol DEFAULT '' NOT NULL
GO