Check constraints on clustered columns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    Check constraints on clustered columns

    Hi guys 'n gals, I'm having an issue wrapping my head around a check constraint that I need to set on a table in my database.

    Table: OnCall
    Columns: OnCall_PKey (identity), Person_Key, StartDate, EndDate

    When a new record is entered, I need a check constraint to make sure that the person entered does not already exist in the table with an overlapping time period:

    If in the new record, the start date or the end date fall between the start date and the end date for an existing record having the person key in the new record then the record fails the check.

    Example:
    One existing data row from my table:
    1496, 06/12/2007, 12/12/2007

    I try to add:
    1496, 09/12/2007, 15/12/2007

    The record fails because the new date range overlaps the existing record in the table. No person can have overlapping time periods, however, a person can have multiple time slots in the table, it's just that none of the time slots may overlap.

    Any pointers, will be gratefully received.
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    What about defining a trigger on the table ?

    Comment

    Working...