Solved

Add Default GetDate to SQL 2005 datetime field

Posted on 2009-05-19
5
751 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

747 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

12 Experts available now in Live!

Get 1:1 Help Now