Search code examples
sqlsybasesap-ase

How to get the current datetime in add column script in sybase


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

Solution

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

    for example:
     alter table test add col3 datetime default getdate() null