views:

50

answers:

1

I have an existing column in my SQL Server database. I have tried about everything I can think of but can not get a default value to be added to the column. What works in every other database is

alter table mytable 
  alter column mycolumn set default(now()) --mycolumn is a datetime

How do I do this in SQL Server?

The error I get for that exact syntax is incorrect syntax near the keyword 'set'

+7  A: 

Use:

ALTER TABLE dbo.mytable
ADD CONSTRAINT def_mycolumn DEFAULT GETDATE() FOR mycolumn

For more info, see: Working with Default Constraints

OMG Ponies
Added the `for` bit for you..
Earlz
@Earlz: Saw that, most appreciated :)
OMG Ponies
now just have to wait 3 more minutes...
Earlz