Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi, I have created a table with a smalldatetime field. I was wondering if there was any way I could have the current date inserted automatically when the row is created?If not can anyone suggest or show me a couple lines of T-SQL for how this can be done manually (if possible)?cheers
Hippi
Yak Posting Veteran
63 Posts
Posted - 2005-01-18 : 01:34:30
quote:Originally posted by darenkov Hi, I have created a table with a smalldatetime field. I was wondering if there was any way I could have the current date inserted automatically when the row is created?If not can anyone suggest or show me a couple lines of T-SQL for how this can be done manually (if possible)?cheers
You can create a table with a column having the default value of the current date. If I remember exactly, there is an example in BOL.HTH
JimL
SQL Slinging Yak Ranger
1537 Posts
Posted - 2005-01-18 : 13:21:19
Default value Getdate()JimUsers <> Logic
X002548
Not Just a Number
15586 Posts
Posted - 2005-01-18 : 14:34:47
Jim's the man with a plan
USE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99(Col1 int IDENTITY(1,1), Col2 datetime DEFAULT(GetDate()), Col3 char(1))GOINSERT INTO myTable99(Col3)SELECT 'x' UNION ALLSELECT 'y' UNION ALLSELECT 'z'GOSELECT * FROM myTable99GOSET NOCOUNT OFFDROP TABLE myTable99GO