title: SQL Server After Insert and After Update trigger
body: <p>I need to create after insert and after update trigger. If the new row is inserted in table, it should run after insert trigger and put timestamp in other table. But if this row is edited again, it should update the other table also. </p>
  
  <p>The status can be changed to active, pending etc. So when each status changes, I need to put timestamp. And for every new record I need to put new row. </p>
  
  <p>Here is the table structure:</p>
  
  <pre><code>| ID | Name | Status |
  |----|------|--------|
  | 1  | xyz  | Active |
  |    |      |        |
  |    |      |        |
  </code></pre>
  
  <p>Let's say this is new row inserted in table, so it should be inserted into another table. But when I change its status, it should update the other table against this ID.</p>
  
  <pre><code>| ID | Name | Active Staus | Other Status |
  |----|------|--------------|--------------|
  | 1  | xyz  | TimeStamp    | Time Stamp   |
  |    |      |              |              |
  |    |      |              |              |`
  
  
   USE [DemoDB]
  GO
  
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER TRIGGER [dbo].[test_INSERT]
         ON [dbo].[Demo]
  AFTER INSERT
  AS
  BEGIN
         SET NOCOUNT ON;
  
         DECLARE ID BIGINT
         Declare @status varchar(50)
         SELECT @ID = INSERTED.ID 
  
         FROM INSERTED
  
         INSERT INTO [dbo].[LogTble]
         VALUES(@ID,'timestamp')
  END
  </code></pre>