Solved

Add Default GetDate to SQL 2005 datetime field

Posted on 2009-05-19
5
789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 60

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 60

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

630 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