Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2006-05-12 : 15:15:20
|
| How to set up default value in a OrderDate field as today's date? So that if new data insert into table, OrderDate will auto fill today's date? |
|
|
Sun Foster
Aged Yak Warrior
515 Posts |
Posted - 2006-05-12 : 15:16:53
|
| I got it. Add getdate |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2006-05-12 : 15:19:44
|
| ALTER TABLE YourTable ADD CONSTRAINT def_YourColumn (or whatever you want to name it) DEFAULT GETDATE() FOR YourColumn WITH VALUESGOYou can check out ALTER TABLE in BOL for more details.Tara Kizeraka tduggan |
 |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-05-12 : 15:19:59
|
| Put getdate() in the Default ValueSrinika |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-14 : 10:17:31
|
use dateadd(day, datediff(day, 0, getdate()), 0) if you want default to today's date without the time (or time = 00:00:00) KH |
 |
|
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2006-05-14 : 10:54:25
|
CURRENT_TIMESTAMP Important that the column does not allow null, otherwise the default will not bite.nullable column, you need to do this:insert orders(...,OrderDate) values(...,default)not null:insert orders(...) values(...)rockmoose |
 |
|
|
|
|
|