使用时间段(15 分钟)将教师和班级都标记为忙碌。
-- Teacher TCH exists.
--
teacher {TCH}
PK {TCH}
-- Class CLS exists.
--
class {CLS}
PK {CLS}
-- Time slot number SLT, starting at STA is 15 min long.
--
tslot {SLT, STA}
PK {SLT}
-- data sample
(SLT, STA)
---------------
(1, '00:00')
, (2, '00:15')
, (3, '00:30')
, (4, '00:45')
, (5, '01:00')
-- ...
, (95, '23:30')
, (96, '23:45')
-- This is a "static" table, once populated make it read-only.
从应用程序级别,填充此表中的所有槽
基于教师、班级、开始时间和给定日期的结束时间。
确保它是在事务中完成的,因此错误会回滚所有内容。
-- On date DTE, teacher TCH is busy with class CLS
-- during time slot number SLT.
--
busy {DTE, SLT, TCH, CLS}
PK {DTE, SLT, TCH}
AK {DTE, SLT, CLS}
FK1 {SLT} REFERENCES tslot {SLT}
FK2 {TCH} REFERENCES teacher {TCH}
FK3 {CLS} REFERENCES class {CLS}
注意:
All attributes (columns) NOT NULL
PK = Primary Key
AK = Alternate Key (Unique)
FK = Foreign Key
这远非完美,它可能会被随机更新搞砸,比如在课堂中间的某个位置更换老师。因此,应用程序应该强制执行规则以防止出现奇怪的条目。