471,893 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,893 software developers and data experts.

How to setup default value using GETDATE?

kai
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at
table design windows for "OrderDate" using GETDATE(), but it does not work.
How do I use setup GETDATE default value for date type? Thanks

Kai
Jul 20 '05 #1
2 51317
On Sun, 09 May 2004 03:39:07 GMT, kai wrote:
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at
table design windows for "OrderDate" using GETDATE(), but it does not work.
How do I use setup GETDATE default value for date type? Thanks

Kai


Hi Kai,

ALTER TABLE MyTable
ADD DEFAULT GETDATE() FOR MyColumn
go

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 20 '05 #2
What do you mean exactly by 'it does not work'? Note that the default value
is used only when the column is omitted from the INSERT column list.

To add to Hugo's response, it's a good idea to name constraints explicitly
so that subsequent schema maintenance is easier:

ALTER TABLE MyTable
ADD CONSTRAINT DF_MyTable_MyColumn
DEFAULT GETDATE() FOR MyColumn

--
Hope this helps.

Dan Guzman
SQL Server MVP

"kai" <ka******@earthlink.net> wrote in message
news:vJ*****************@newsread3.news.atl.earthl ink.net...
Hi, All
On Northwind database in SQL Server 2000, I try to setup default value at table design windows for "OrderDate" using GETDATE(), but it does not work. How do I use setup GETDATE default value for date type? Thanks

Kai

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by erick-flores | last post: by
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.