无法为XOR关系找到一致的非还原数据模型

时间:2015-11-03 08:18:11

标签: oracle database-design data-modeling foreign-key-relationship xor

在我的数据模型中,我有一个XOR /互斥/弧关系。我找到了一些文档如何建模这种关系(例如http://www.sqlteam.com/article/implementing-table-inheritance-in-sql-server

。)模型方法

Person (PersonID*, PersonTypeID)
Student (PersonID*, PersonTypeID=1, EnrollmentDate) --is a person
Teacher (PersonID*, PersonTypeID=2, HireDate) --is a person

在PersonID + PersonTypeID上定义唯一键约束我可以在PersonID + PersonTypeID列上创建外键约束以确保XOR。

我喜欢这种方法,因为我不需要任何触发器或检查约束。

。)问题

在我的情况下,我有一个级别,让我们说一个Super_Person,其中存储了PersonTypeID:

Super_Person (Super_Person_ID*, PersonTypeID)
Person (PersonID*, PersonTypeID (???), Super_Person_ID) --is a Super_Person
Student (PersonID*, PersonTypeID=1, EnrollmentDate) --is a person
Teacher (PersonID*, PersonTypeID=2, HireDate) --is a person

要创建外键约束(Student-Person和Teacher-Person),我需要Person表中的PersonTypeID。但PersonTypeID实际上存储在Super_Person中。因此需要一个触发器来将PersonTypeID从Super_Person传播到Person,我不想这样做,因为它是冗余信息。

有关如何很好地建模的任何建议吗?谢谢!

0 个答案:

没有答案