Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having to design a table which contains scheduled times for media to be displayed. These scheduled times should not overlap.

In my SheduledSlot table I have:

id    integer PRIMARY KEY
begin datetime(or integer for SQLite)
end   datetime(or integer for SQLite unixtime)
media_item integer (foreign key)

How do I enforce a constraint which ensures a unique time range for each scheduled item?

share|improve this question

You should implement this on the database side in the method that can be called by your create schedule time and modify schedule time methods.

share|improve this answer

You can implement such a functionality using triggers. It can be INSTEAD INSERT/UPDATE or BEFORE INSERT/UPDATE trigger depends on RDMS you are using. In the trigger body you raise an error if the new data does not pass validation.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.