Solved

Add Default GetDate to SQL 2005 datetime field

Posted on 2009-05-19
5
767 Views
Last Modified: 2012-05-07
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
Comment
Question by:BothWorldsJo
  • 2
  • 2
5 Comments
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24424866
ALTER TABLE dbo.cvupload ALTER COLUMN AddedDT SET default (GetDate())
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 250 total points
ID: 24424921
alter table dbo.cvupload
add constraint df_dtfld default (getdate()) for addeddt
0
 
LVL 59

Expert Comment

by:Kevin Cross
ID: 24424961
Nice Tim, I forget that SET DEFAULT doesn't work in SQL 2005.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 24424993
:)  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
 

Author Comment

by:BothWorldsJo
ID: 24425149
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now