13

In Microsoft SQL server, how can I add/change the default on an existing table column using T-SQL?

1 Answer 1

17
ALTER TABLE yourTable ADD  CONSTRAINT constraintName  
   DEFAULT ('XYZ') FOR [YourColumn]

To change the default, drop the constraint and re-add it with the new value:

ALTER TABLE yourTable
DROP CONSTRAINT constraintName

ALTER TABLE yourTable ADD  CONSTRAINT constraintName  
   DEFAULT ('ABC') FOR [YourColumn]
1
  • Can also do it in the designer. Commented Jul 14, 2011 at 1:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.