Showing posts with label to an existing table in SQL Server. Show all posts
Showing posts with label to an existing table in SQL Server. Show all posts

Sunday, February 8, 2015

Add a column, with a default value, to an existing table in SQL Server



Syntax


 ALTER TABLE {TABLENAME}   
 ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}   
 CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}  
 [WITH VALUES]  

Example


 ALTER TABLE table  
 ADD column BIT   
 CONSTRAINT Constraint_name DEFAULT 0 WITH VALUES  


Note : WITH VALUES handles the NOT NULL part...