title: SQL Triggers - Deleted or Updated? or maybe something else?
body: <p>I am trying to figure out which i need to use here: deleted, inserted or updated.</p>
  
  <p>basically.</p>
  
  <p>I need to write some data to the history table, when the main table is updated, and only if the status changes from something to either pending or active.</p>
  
  <p>This is what I have now:</p>
  
  <pre><code>ALTER TRIGGER [dbo].[trg_SourceHistory]  ON [dbo].[tblSource]
  FOR UPDATE AS  
      DECLARE @statusOldValue char(1) 
      DECLARE @statusNewValue char(1)
  
      SELECT @statusOldValue = statusCode FROM deleted 
      SELECT @statusNewValue= statusCode FROM updated
  
      IF (@statusOldValue &lt;&gt; @statusNewValue) AND 
         (@statusOldValue = 'P' or @statusOldValue = 'A')
      BEGIN TRY
         INSERT * INTO tblHistoryTable)  
             select * from [DELETED]
  </code></pre>
  
  <p>so I want the new data to stay in the main table, the the history table to be updated with what is being overwritten... right now it just copies the same info over. so after update, both my tables have the same data.</p>