title: T-SQL Trigger INSERT UPDATE
body: <p>I'm fairly new in T-SQL but i have a question concerning triggers. I have written a trigger that is used in my stored procedure witch inserts and updates data. </p>
  
  <p>Now the trigger works when any row is updated in table <code>[dbo].[users]</code> </p>
  
  <p>I don't know how to modify this trigger so that if data is inserted into <code>[dbo].[users]</code> table activate the trigger (this works now), but how to acheive an update scenario on the same trigger that if only a specific row is UPDATED in <code>[dbo].[users]</code> table that only then the trigger should be activated. </p>
  
  <p>For example </p>
  
  <ol>
  <li><p>If a new user is inserted and all rows are inserted in this table - activate trigger</p></li>
  <li><p>If an old trigger is updated but only a specific field in this table is updated (working_state is the name of a  column) then only should the trigger should be activated.</p></li>
  </ol>
  
  <p>Source code what I have is shown here:</p>
  
  <pre><code>ALTER TRIGGER [dbo].[t_temp_triger_name] 
  ON [dbo].[users] 
  AFTER INSERT, UPDATE, DELETE 
  AS
  BEGIN
      DECLARE @working_state char(1),
              @user_code char(11)
  
      DECLARE zm CURSOR FOR
          SELECT
              working_state,
              user_code
          FROM
              inserted
  -- Added update statement that activates the trigger only when a specific -
  -- column update is executed 
  UPDATE  [dbo].[users]
  SET working_state = 1
  FROM  [dbo].[users] U 
  INNER JOIN DELETED D ON U.user_code= D.user_code
  WHERE U.working_state&lt;&gt; D.working_state
  
  
      OPEN zm
  
      FETCH NEXT FROM zm INTO @working_state, @user_code
  
      WHILE @@FETCH_STATUS = 0
      BEGIN
          EXEC [FNF].[dbo].[NamedProcedure] 
                  @working_state, @user_code
  
          FETCH NEXT FROM zm INTO @working_state, @user_code
      END
  
      CLOSE zm
      DEALLOCATE zm   
  END 
  </code></pre>