I am using SQL Server CE and I have a table [accounts]
. I was modifying the column [ondate]
so that it can have a default of GetDate
.
My query is
ALTER TABLE [accounts]
ALTER COLUMN [ondate] DATETIME NULL DEFAULT GETDATE()
But I get this error :
Token in error = DEFAULT
I have tried getdate
without parenthesis, with single quotes (') but the error is still the same.
How to modify the column [ondate]
to have default of getdate
?
Here is the correct syntax
ALTER TABLE accounts ADD DEFAULT getdate() FOR [ondate]
It is always better to add a name to constraints
ALTER TABLE accounts ADD CONSTRAINT DF_ONDATE_GETDATE DEFAULT getdate() FOR [ondate]