Search code examples
sybasesap-ase

add a getdate() default value while adding a column


Useally if I want to add default value , I use this way

ALTER TABLE tab1 ADD  coll datetime DEFAULT '11-01-15' NOT NULL

however I want to add default value as the getdate().
so If use the below I got the below error

ALTER TABLE tab1 ADD  coll datetime DEFAULT GETDATE() NOT NULL

error: ALTER TABLE 'tab1' failed. Default cannot be an expression when adding non-NULL column 'tab1'. Use a default value instead.

what I want is the default value is the getdate(). how to do that when adding a new datetime column ?


Solution

  • I solved my question by adding the column to null

    alter table tab1 add col1 datetime default getdate() null
    

    then I modify it to not null