7

How do I add a column, with a default value, to an existing table in SQLServer 2008?

0

2 Answers 2

20

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

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

Sign up to request clarification or add additional context in comments.

Comments

9

Use ALTER TABLE. For example

ALTER TABLE Table1 
ADD  col2 INT DEFAULT 0;

SQLFiddle

2 Comments

As a general rule, it is best to name your constraints. If you don't it will get a random name, and they will differ between different databases (eg at different client installations). This will make scripting changes difficult in some cases (ie you will have to resort to workarounds).
@TT. Fair point. Agreed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.