title: How to execute a TRIGGER in MSSQl?
body: <p>Am having two table like <em>Student</em> and <em>StudentHistory</em> in SQL Server, if any change happen in the <em>Student</em> table that Trigger should update <em>StudentHistory</em> table. </p>
  
  <p>Tables:</p>
  
  <pre><code>CREATE TABLE Student (
    Id int,
    Name varchar(20),
    Dept varchar(10),
    Age int,
    Cratedby int,
    CreatedTime datetime,
    Modeifideby int,
    ModifiedTime datetime,
    Flag varchar(5)
  )
  </code></pre>
  
  <p>History table,</p>
  
  <pre><code>CREATE TABLE StudentHistory (
    Id int,
    Actiontaken varchar(50),
    ActionTime dateTime,
    Cratedby int,
  )
  </code></pre>
  
  <p>Trigger,</p>
  
  <pre><code>CREATE TRIGGER  wsrd.tr_Student on
  wsrd.Student
  AFTER INSERT
  AS
  
  insert into wsrd.StudentHistory
             (Actiontaken,ActionTime,Cratedby) 
      (SELECT concat('Inserted-',i.id),i.CreatedTime,i.Cratedby from wsrd.Student s, inserted i where s.id=i.Id);
  GO 
  </code></pre>
  
  <p>The condition is,</p>
  
  <ol>
  <li>Trigger should get execute only if column Modeifideby, ModifiedTime  and Flag is inserted in the Student table.
  
  <ol start="2">
  <li>If Id,Name, Dept , age, CreatedTime and Flag inserted means that trigger should not get execute.</li>
  </ol></li>
  </ol>
  
  <p>How can achieve this?</p>