?
Solved

SQL Server: table row insert/update datetime

Posted on 2014-07-25
3
Medium Priority
?
1,510 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 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
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…
Suggested Courses

800 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