Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ALTER COLUMN

Status
Not open for further replies.
Joined
Apr 27, 1999
Messages
705
Location
US
Hello,

I have a column called CREATED that currently has DateTime as its field value.

I just learned that I can have it default to the a date time by using the function getdate().

Here's what I have, but it keeps getting an error near DEFAULT when I try to validate the syntax.

Thanks for the help in advance.
fengshui


ALTER TABLE Applicants
ALTER Column Created datetime NOT NULL DEFAULT (getdate())

 
I believe the issue is when you add the default. If you add it when the column is being created, the syntax is:

ALTER Table Applicants
ADD Created datetime NOT NULL DEFAULT (getdate())

But when the column already exists, the syntax is different:

ALTER Table Applicants
ADD CONSTRAINT created_default
DEFAULT getdate() FOR Created

-SQLBill

The following is part of my signature block and is only intended to be informational.
Posting advice: FAQ481-4875
 
Thanks but now I am getting the error "Column already has a DEFAULT bound to it. Could not create constraint.
 
Never mind. I found my answer, DROP the constraint and then ALTER.


Thanks,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top