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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 To getdate() or not to getdate()

Author  Topic 

marshallartist
Starting Member

3 Posts

Posted - 2008-03-13 : 09:10:01
I am setting up a table and I want to capture the creation date of each record when it comes in. Obviously the easy way to do this is set the dfault value of this field to getdate(), but I am wondering if there is a benefit to using an insert trigger instead?

I will also be adding a seperate updatedOn field and plan to use an update trigger to populate it. If there is a better way to do either of these please let me know.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-03-13 : 09:13:01
Trigger will add additional overhead at the best, if you plan to use trigger just to set default value.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-13 : 09:14:30
A CreatedOn column will easily be made with a default value. No need for an insert trigger.
An UpdatedOn column will easily be made with an update trigger.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

marshallartist
Starting Member

3 Posts

Posted - 2008-03-13 : 09:15:38
Thanks
Go to Top of Page
   

- Advertisement -