Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 799
  • Last Modified:

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
0
BothWorldsJo
Asked:
BothWorldsJo
  • 2
  • 2
1 Solution
 
Kevin CrossChief Technology OfficerCommented:
ALTER TABLE dbo.cvupload ALTER COLUMN AddedDT SET default (GetDate())
0
 
chapmandewCommented:
alter table dbo.cvupload
add constraint df_dtfld default (getdate()) for addeddt
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now