Domanda

I need to add the current datetime to ALTER TABLE ADD Column (not null) script. I tried following and got below error

alter table table1 add created_by varchar(20) default '' not null , create_date datetime default getDate() not null , last_updated_by varchar(20) default '' not null,last_update_date datetime default getDate() not null

Could not execute statement.
ALTER TABLE 'table1' failed. Default cannot be an expression
when adding non-NULL column 'create_date'. Use a default value instead.
Sybase error code=13918
Severity Level=16, State=1, Transaction State=1
Line 1
È stato utile?

Soluzione

You can use getdate as default if you specify column as null

for example:
 alter table test add col3 datetime default getdate() null
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top