GetSLN Software GetSLN Software - 1 month ago 6
SQL Question

sqlce alter column Token in error = DEFAULT

I am using sqlce and i have a table [accounts]. I was modifying the field [ondate] so that it can have Default GetDate.

My query is

alter table [accounts] ALTER COLUMN [ondate] datetime NULL DEFAULT getdate()


But its showing error


Token in error = DEFAULT


I have Tried 'getdate' without parenthesis, with single quotes (') but the error is same.

How to modify the field [ondate] to have 'default getdate' ?

Answer

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]