Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting DATETIME for rows inserted/Modified

am using SQL server 2005 , i have a requirement to get the Creation datetime of all the rows in a particular table, unfortunately the table do not have any "rowverion" or datetime column ( i know this is a major design flaw).

so , i was wondering if SQL server maintains datetime for each row inserts.

comments suggestions appreciated

Regards Deepak

like image 590
DEE Avatar asked Apr 08 '26 14:04

DEE


1 Answers

No, SQL Server does not timestamp the rows automatically when they are created. As you suggested, for the future, you may want to create a new date_created column and set it default to GETDATE():

ALTER TABLE       your_table  
  ADD CONSTRAINT  dc_your_table_date_created
  DEFAULT         GETDATE()
  FOR             date_created;

You may also use a trigger instead, if you prefer, as @Vash suggested in the other answer.

like image 53
Daniel Vassallo Avatar answered Apr 11 '26 03:04

Daniel Vassallo