Solved

SQL Server: table row insert/update datetime

Posted on 2014-07-25
3
1,466 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 66

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
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…

688 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