Add Default GetDate to SQL 2005 datetime field

Hi!
In SQL, I have a table cvupload that has a datetime field AddedDT. I want to programmatically add a default of GetDate to the field but keep getting errors.  There is no default in the field so far.
These don't work -
ALTER TABLE dbo.cvupload ALTER COLUMN AddedDT datetime not null default 'GetDate()'
ALTER TABLE dbo.cvupload ALTER COLUMN AddedDT datetime not null default GetDate()
GO
Thanks!
Jo
BothWorldsJoAsked:
Who is Participating?
 
chapmandewConnect With a Mentor Commented:
alter table dbo.cvupload
add constraint df_dtfld default (getdate()) for addeddt
0
 
Kevin CrossChief Technology OfficerCommented:
ALTER TABLE dbo.cvupload ALTER COLUMN AddedDT SET default (GetDate())
0
 
Kevin CrossChief Technology OfficerCommented:
Nice Tim, I forget that SET DEFAULT doesn't work in SQL 2005.
0
 
chapmandewCommented:
:)  No problem.  The SET part actually looked funky to me, that was the only reason I chimed in.  Usually if I see you've posted I assume the question has been answered and I move on.  
0
 
BothWorldsJoAuthor Commented:
Thanks for the constraint, the Set did error as you thought.

Can't believe the speed of you both - Thanks again!
Jo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.