title: SQL Server 2008 FOR INSERT trigger not working
body: <p>I am studying the trigger and I got a question.</p>
  
  <p>I am creating a trigger to change the time complex.</p>
  
  <p>In the data table <code>weeklymeeting</code></p>
  
  <pre><code>|section_id| meeting type| days| timestart|timeend|class_id|
  | 13       | Lecture     |   5 | 01:00:00 |02:00:00|12     |
  </code></pre>
  
  <p><code>timestart</code> and <code>timeend</code> are of datatype <code>TIME</code></p>
  
  <p>I am creating the trigger that checking the time complex</p>
  
  <p>for example </p>
  
  <p>if user uses query like</p>
  
  <pre><code>INSERT INTO DBO.WeeklyMeetings VALUES (35, 1,1 ,'11:40:00','11:42:00', 42)
  </code></pre>
  
  <p>it should insert the data </p>
  
  <p>however </p>
  
  <pre><code>INSERT INTO CSE132B.DBO.WeeklyMeetings VALUES (35, 1, 1, '12:30:00','01:30:00', 42)
  </code></pre>
  
  <p>then it must return error message because it is time complex </p>
  
  <p>Therefore I created a trigger to check the time complex..but such as</p>
  
  <pre><code>ALTER TRIGGER [dbo].[check_section_time_complex] ON [dbo].[WeeklyMeetings]
  FOR INSERT AS
  IF EXISTS(select * from inserted as i INNER JOIN dbo.WeeklyMeetings as m  ON (i.timestart BETWEEN m.timestart and m.timeend)  
  OR( i.timeend BETWEEN m.timestart and m.timeend ))
  begin
   RAISERROR ('Can not update data because  section time is complexing with other section!!', 16,1);
  rollback tran
  end
  </code></pre>
  
  <p>however,  it is not really working...i am not really sure that reason....</p>
  
  <p>does anyone knows problems in this trigger ?</p>
  
  <p>thanks</p>