How to set a default value for an existing column

Nakul Chaudhary picture Nakul Chaudhary · Jul 22, 2011 · Viewed 676.9k times · Source

This isn't working in SQL Server 2008:

ALTER TABLE Employee ALTER COLUMN CityBorn SET DEFAULT 'SANDNES'

The error is:

Incorrect syntax near the keyword 'SET'.

What am I doing wrong?

Answer

Yuck picture Yuck · Jul 22, 2011

This will work in SQL Server:

ALTER TABLE Employee ADD CONSTRAINT DF_SomeName DEFAULT N'SANDNES' FOR CityBorn;