【发布时间】:2014-10-21 14:39:18
【问题描述】:
在时间表数据模型中,假设我有以下父表:
CREATE TABLE EmployeeInRole (
employeeInRoleId PRIMARY KEY,
employeeId,
roleId,
rate,
effectiveFrom DATE, --from when can this employee assume this role
effectiveTo DATE
);
以及以下子表:
CREATE TABLE TimesheetEntry (
startTime DATETIME,
endTime DATETIME,
employeeInRoleId,
CONSTRAINT fk FOREIGN KEY (employeeInRoleId) REFERENCES EmployeeInRole (employeeInRoleId)
);
当我插入TimesheetEntry 时,我想确保该时间段在父记录的effectiveFrom/To 的边界内。
是否可以在不使用触发器的情况下将此约束构建到 DDL 中,还是我必须通过触发器或在应用程序级别维护此约束?
【问题讨论】:
标签: sql database-design