March 30, 2007 at 12:08 pm
In table designer in SQL 2000 I have a column that has a definition of smalldatetime and I want it to default to the current datetime for any row insert. What syntax do I use to default this column ? I cannot seem to find an answer in BOL.
March 30, 2007 at 12:38 pm
Getdate() should work like a charm. Is that giving you errors of some sort?
March 30, 2007 at 12:43 pm
That is it !!! Thanks, I was drawing a blank for some reason on it....
March 30, 2007 at 12:50 pm
No problem at all. I was going to say you can also use the niladic function CURRENT_TIMESTAMP, but it just turns it into Getdate() anyway, so might as well cut out the middleman.
March 30, 2007 at 12:54 pm
I was toying with the idea of that myself. I used DTS to bring the table definition/data from DB2 and that is how it created it.
Thanks for the answer. I knew it was simple, just could not think of it...
April 2, 2007 at 1:11 am
If you want the day only, without the time part you could use:
convert(char(8), getdate(), 112)
There are other solutions, but I like this one.
April 2, 2007 at 4:17 am
Henk, if he uses that as the default for a smalldatetime column, it will convert it right back into a date (it will lose the formatting that style 112 applied to it), including time (although the time will be midnight).
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply