Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you tell me when data was inserted into a table

I am using MS SQL Server 2008 and I have an sql table with some data that is inserted daily at 6 am by an sql job. The problem I have is that some data has been inserted separately into the job and I need to know when this data was added.

Is there a query I can run that will show me this?

like image 792
Silentbob Avatar asked Jul 12 '13 07:07

Silentbob


2 Answers

I think the short answer is NO, there's no magic, ad hoc SQL query that will let you go back after the fact and find out when a row was inserted.

If you want to know when a row is inserted, the easiest thing would be to simply add a date or timestamp field with a default value (like getDate()) that automatically fills in the date/time when the row is inserted.

There are, of course, SQL logs available that will let you track when rows are inserted, updated, deleted, etc., but those require set up and maintenance.

Third option would be to have the program that's inserting the data perform some logging.

like image 160
Brian Avatar answered Sep 27 '22 21:09

Brian


Add a date field to the table. You can give it a default value of GETDATE()

Then ORDER BY that field.

SELECT Column1, Column2, NewDateColumn
FROM YourTable
ORDER BY NewDateColumn
like image 20
Darren Avatar answered Sep 27 '22 19:09

Darren