title: Auto update time in SQL Server
body: <p>I would like to have two columns in my table to store the add-time and update-time. As the name suggests, the add-time is the time when a row was first added; the update-time is the last time a row was updated. I can implement first by defaulting value to <code>GETDATE()</code>. As for the second, @Jeremy suggested using triggers here:</p>
  
  <p><a href="https://stackoverflow.com/questions/2713339/on-update-auto-update-date-time-field">On Update: Auto Update Date/Time Field</a></p>
  
  <ol>
  <li>Is there any easier way?</li>
  <li>If I implement a trigger, does that mean two <code>UPDATE</code> statements (or one <code>INSERT</code> and one <code>UPDATE</code> in case the row is just created) have to be executed?</li>
  </ol>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong> For the second part of the question, this is the trigger I have in my database:</p>
  
  <pre><code>CREATE TRIGGER [dbo].[TR_AddUpdateTime]
     ON [dbo].[AddUpdateTime]
     AFTER UPDATE
  AS 
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      -- Insert statements for trigger here
  
      UPDATE r
         SET UpdateTime = GETDATE()
        FROM AddUpdateTime r
        JOIN inserted i
          ON i.Id = r.Id
  END
  </code></pre>
  
  <p>Does this mean that an additional update statement will be executed whenever I make an update to AddUpdateTime table, or MSSQL is smart enough to recognise that I am updating the same record and save both changes at the same time?</p>