April 12, 2005 at 3:11 am
Hiya,
I have a table open in EM. Is there a way to enter a current timestamp into a datetime/smalldatetime field?
Very much like CTRL-0 inserts NULL.
TIA
Jamie Thomson
http://sqlblog.com/blogs/jamie_thomson
April 12, 2005 at 3:36 am
TIA,
There is no way I know of to automatically (unless anyone else knows better??) insert the current datetime in to a table open within EM unless the COLUMN has a default constraint set using the SQL getdate() function.
Your other options are:
- Write a SQL INSERT statement such as below which captures the current datetime using the getdate function:
INSERT INTO tablename (column1, column2, datetimecolumn) VALUES('Value1', 'Value2', getdate())
- Modify your table to have a default constraint set (as mentioned above):
ALTER TABLE tablename ADD CONSTRAINT 'constraintname' DEFAULT (getdate())
It's worth noting that adding a constraint could have undue effects across the capture of dates and times within your database as if a datetime is not specified the current datetime will be captured by default.
- Your last option is to be lazy and simply add the datetime in yourself in the correct format:
30/03/2005 17:01:33
Hope this helps,
Lloyd
April 12, 2005 at 3:40 am
That's fine Lloyd. I'm fine with writing SQL or using constraints, I'm just lazy that's all.
By the way, TIA is an acronymn, not my name! (It stands for Thanks In Advance)
Jamie Thomson
http://sqlblog.com/blogs/jamie_thomson
April 12, 2005 at 4:01 am
Ok no probs, my ALTER TABLE script was wrong, should have read:
ALTER TABLE tablename
ADD CONSTRAINT 'constraintname' DEFAULT (getdate()) FOR 'columnname'
Lloyd
April 13, 2005 at 8:50 am
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply