Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 9 down vote accepted
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]
share|improve this answer
    
Can also do it in the designer. – SqlSandwiches Jul 14 '11 at 1:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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