October 1, 2002 at 11:42 am
What is the best method to finding the most recent record added? Example: My table has 10 records on one person, how do I retrieve the record that was added to the table last for that one person? I'm in the process of building the tables and am not sure about using Time-stamping. Am I on the right track?
October 1, 2002 at 11:54 am
You will need to determine what it is you really want. A timestamp column will change if you update the row. Therefore it might not be the best if you want to know when the record was added. Typically I use a datatime column and give that column a default value of "getdate()". This will populate this field when the record is added with the current date unless you specifically set the datetime column when adding records. The datetime column will also not change when updating the record, unless you specifically change the timestamp column as part to the update command. One drawback to using a datetime is it is possible that more than one record could have the same datetime applied, if they where added within 3 milliseconds of each other, or where added via a bulk insert process.
Hope this gives you something to go on.
Also note that timestamp is being replaced with rowversion in future release of SQL Server.
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply