Solved

SQL Server: table row insert/update datetime

Posted on 2014-07-25
3
1,440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40219923
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
ID: 40219924
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:Scott Pletcher
ID: 40219957
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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

733 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