12

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

Nick Chammas
  • 14,170
  • 17
  • 73
  • 119
Russell Steen
  • 352
  • 1
  • 2
  • 8

1 Answers1

16
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]
SqlACID
  • 2,188
  • 15
  • 16