Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to know the date when the row was inserted into a table in sql server. I want to know the date for updating the values from the concerned date.
Posted

If you have the proper logging enabled you might find it in there, but SQL does not store an insertion date for each row.

If you need this than you need to include the date[^] into your table design.
You can use CREATE DEFAULT[^] so that newly added rows get the current date automatically.
 
Share this answer
 
Comments
Anaya Upadhyay 26-Nov-12 4:34am    
I agree to your answer, but...

As we get the last modified date of a table, can't we get the last modified or inserted date of a row??

I need to know the actual inserted/updated date of a row while selecting the table. Help.
André Kraak 26-Nov-12 4:38am    
As long as you store these dates with the row yourself, you can.

So add a creation/insertion date and mutation date to the table and fill them. Then you can use them to select your rows.
Prasad Guduri 27-Nov-12 4:04am    
Until you store these details in database it is not possible to get those details...!!!!

Maintain a separate column in table to store record created date&time.
for storing insertion detail's datetime
create column say it InsertionDate
now, set it's default value = GetDate()

for update datetime
create column say it UpdateDate
1. now, set it's value when updating query
example: update tbl set updateDate=getdate(),col1=1,col2='hello' where ...
2. or set column's datatype = timestamp column

Happy Coding!
:)
 
Share this answer
 
Thank you for your help.

But i had some thousand rows already in my table. I just wanted to know the row insertion date to simply add english date to a new column for each row.

I solved it by converting nepali date (which was already in the table) to english date to this new column.

Thank you all again.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900