Solved

SQL Server: table row insert/update datetime

Posted on 2014-07-25
3
1,367 Views
Last Modified: 2014-08-04
Hi, how can I find table row insert and last update datetime?
Thanks.
0
Comment
Question by:quasar_ee
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
Comment Utility
The only way to pull that off is if there are columns to hold values for insert datetime and update datetime, and the inserting/updating query populates them.

Or, if the table has some kind of trigger which auto-magically adds them.

Otherwise, what you are asking is not possible.
0
 
LVL 13

Expert Comment

by:Russell Fox
Comment Utility
If you don't have a specific column to track that data, you'll need to go looking through the log files to find it. I always have DateCreated (default  = GETDATE()) and DateUpdated DATETIME columns in all relevant tables. Data is only updated through our stored procedures, so all updated procs do a "SET DateUpdated = GETDATE()". If you don't control your inputs with stored procedures or other code, you can also put in an ON UPDATE trigger to update that column whenever a record is changed, and that will fire even if you change bulk records through a query in Management Studio.
0
 
LVL 69

Expert Comment

by:ScottPletcher
Comment Utility
But be aware that you're widening the rows, and thus affecting overall performance of the table, by adding these columns.

Instead, if possible, I suggest using a trigger and storing that data in a separate table.  But most people don't do that.  Still, if you have a (very) large table with, say, 100M rows, even an additional 16 bytes per row is 1.6B bytes more in the table.  Moreover, many people also store a character id of who added and who changed, widening the row that much more.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now