Reputation: 7377
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 ?
Upvotes: 0
Views: 5107
Reputation: 1
Use the below for Sybase
:
ALTER TABLE table_name
ADD effective_date Datetime DEFAULT "3/16/2009 09:15" NOT NULL
ALTER TABLE table_name
REPLACE effective_date DEFAULT getdate()
Upvotes: 0
Reputation: 7377
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
Upvotes: 2