sql - Opening Hours Database Design -


we developing application in multiple entities have associated opening hours. opening hours may span multiple days, or may contained within single day.

ex. opens monday @ 6:00 , closes @ friday @ 18:00.

or

opens monday @ 06:00 , closes monday @ 15:00.

also, entity may have multiple sets of opening hours per day. far, best design have found, define opening hour consist of following:

startday, starttime, endday , endtime.

this design allows needed flexibility. however, data integrity becomes issue. cannot seem find solution disallow overlapping spans (in database).

please share thoughts.

edit: database microsoft sql server 2008 r2

presuming robust trigger framework

on insert/update check if new start or end date falls inside of existing range. if roll change.

create trigger [dbo].[mytable_iutrig] on [mytable] insert, update  if (select count(*) inserted, mytable (inserted.startdate < mytable.enddate            , inserted.startdate > mytable.startdate)       or (inserted.enddate < mytable.enddate            , inserted.enddate > mytable.startdate)) > 0  begin     raiserror --error number     rollback transaction end 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

sql server - python to mssql encoding problem -

windows - Python Service Installation - "Could not find PythonClass entry" -