469,273 Members | 1,819 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,273 developers. It's quick & easy.

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 51158
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 zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.