title: SQL constraint for between multiple values
body: <p>Here is my table</p>
  
  <pre><code>Events
  Start : Datetime
  End : Datetime
  </code></pre>
  
  <p>I'm trying to make sure that a new Event does not overlap any previously entered events.  I'll admit my SQL knowledge is novice at best.  The following is a select statement that gets me close but I can't figure out how to turn it into a constraint (would I use check?)</p>
  
  <pre><code>SELECT e.*
  FROM Events
  WHERE Start BETWEEN e.START and e.END
  OR End BETWEEN new.START and new.END
  OR (Start &lt; e.Start and End &gt; e.End)
  </code></pre>
  
  <p>I'd imagine if something like that returned anything at all there's overlap.</p>
  
  <p>Edit: updated "sql" statement to cover for a logical failure on my part.  It's most likely still poorly formed.  I really appreciate all of the help!</p>