title: Create trigger that compares dates in SQL Server
body: <p>I'm very new to triggers and I can't seem to wrap my head around them. Let's assume I have two tables here:</p>
  
  <pre><code>CREATE TABLE Project 
  (
      id INT NOT NULL IDENTITY(1, 1),
      startDate DATETIME,
      endDate DATETIME
  );
  
  CREATE TABLE Work 
  (
      date DATETIME,
      projectId INT
  );
  </code></pre>
  
  <p>I insert some data:</p>
  
  <pre><code>INSERT INTO Project VALUES ('2017-04-18', '2017-05-01'); /*id = 1*/
  INSERT INTO Work VALUES ('2017-04-17', 1);
  </code></pre>
  
  <p>Assuming there's only 1 project with <code>id = 1</code>, this should go well. However, it doesn't make much sense that my work starts the day before the project starts (not in this case). How would I create a trigger that basically says <code>date cannot be &lt; startDate OR &gt; endDate</code>?</p>