December 19, 2006 at 11:48 am
IS there a way to track or to identify last records inserted or updated into a database tables,
Thanks for any advice.
December 19, 2006 at 12:36 pm
There is no way out of the box, you could easily develop a solution.
One way would to put a Created_Date field in your table with a default value of Getdate(). So when a record is created it will record the date and time.
December 19, 2006 at 12:53 pm
December 19, 2006 at 12:53 pm
For updating, create a trigger that when an update occurs, it also updates the created_date column (or whatever name you choose).
I suggest that instead of calling it Created_Date, you use something like Version_Date.
-SQLBill
December 20, 2006 at 6:59 am
Don't forget there is a table called "inserted" that contains newly added/updated records which you can access via a FOR INSERT or FOR UPDATE trigger.
January 24, 2007 at 3:58 pm
If all access is via SPs, you could just be sure to refresh "UpdatedDate" field whenever you do an update, rather than using a TRG.
Upside is that it's a bit faster since you won't do a "double hit"; downside is that you cannot be 100% positive every update will happen via an SP, so someone *could* update the row without it getting reset... Whereas a TRG will positively set it.
If going the TRG route... you could also track "UpdatedBy"... and/or could also write this info to an audit table...
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy