Discussion:
Alter using osql
(too old to reply)
Ryan
2007-09-13 22:16:02 UTC
Permalink
Currently, PaymentDate in my table is a SMALLDATETIME and NULL is allowed. I
would like to alter PaymentDate column to be NOT NULL and set its default
value to current date.
I am using the following osql command but it generated an error; could
someone please help?

ALTER COLUMN PaymentDate NOT NULL DEFAULT GETDATE();
Jonathan Psaila-Depasquale
2007-09-14 07:54:33 UTC
Permalink
Hi,

You have to do it in two commands and anyway the command is actually
ALTER TABLE. So try the following:


alter table mydb.dbo.mytable
alter column paymentdate smalldatetime not null

alter table mydb.dbo.mytable
add constraint paymentdate_def default getdate() for paymentdate


Jonathan
Post by Ryan
Currently, PaymentDate in my table is a SMALLDATETIME and NULL is allowed. I
would like to alter PaymentDate column to be NOT NULL and set its default
value to current date.
I am using the following osql command but it generated an error; could
someone please help?
ALTER COLUMN PaymentDate NOT NULL DEFAULT GETDATE();
Ryan
2007-09-17 13:56:00 UTC
Permalink
Thanks, it worked.
Post by Jonathan Psaila-Depasquale
Hi,
You have to do it in two commands and anyway the command is actually
alter table mydb.dbo.mytable
alter column paymentdate smalldatetime not null
alter table mydb.dbo.mytable
add constraint paymentdate_def default getdate() for paymentdate
Jonathan
Post by Ryan
Currently, PaymentDate in my table is a SMALLDATETIME and NULL is allowed. I
would like to alter PaymentDate column to be NOT NULL and set its default
value to current date.
I am using the following osql command but it generated an error; could
someone please help?
ALTER COLUMN PaymentDate NOT NULL DEFAULT GETDATE();
Loading...