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

 Posted by vishalneeraj-24503 on 1/13/2014 | Category: Sql Server Interview questions | Views: 2171 | Points: 40
Answer:

Syntax:-
ALTER TABLE {TABLENAME} 

ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL}
CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}

For Example:-
ALTER TABLE Employee_Master

ADD Employee_Code VARCHAR(20)
CONSTRAINT DF_Employee_Master_Employee_Code DEFAULT '' NOT NULL


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response