考虑这种情况:从销售人员处购买汽车.销售人员在陈列室(仅在一个陈列室)工作.陈列室隶属于制造商,仅销售该制造商生产的汽车.同时,Car是特定型号,而型号由制造商制造.
限制R:汽车模型的制造商必须与汽车销售员的陈列室附属制造商的制造商相同.
该图显示了明显的外键关系.
----> Manufacturer <---- | | | | Showroom | ^ | | Model | ^ Salesperson | ^ | | | --------- Car ----------
你如何执行限制R?您可以添加外键关系Car – >制造商.然而,汽车的制造商可以通过在“钻石”周围以这种或那种方式连接表来建立,所以这肯定不会被规范化吗?然而,我不知道如何强制执行约束.
解决方法
如果我正确地理解了这个问题,那就应该接近了.
这里有一些关键的细节
-- -- Keys for SalesPerson -- alter table SalesPerson add constraint PK_salesperson primary key (PersonID),add constraint AK1_salesperson unique (ManufacturerID,ShowRoomNo,PersonID),add constraint FK1_salesperson foreign key (PersonID) references Person (PersonID),add constraint FK2_salesperson foreign key (ManufacturerID,ShowRoomNo) references ShowRoom (ManufacturerID,ShowRoomNo) ; -- -- keys for Sale table -- alter table Sale add constraint PK_sale primary key (SaleID),add constraint FK1_sale foreign key (BuyerID) references Person (PersonID),add constraint FK2_sale foreign key (ManufacturerID,ModelName,ShowRoomNo) references CarDisplay (ManufacturerID,ShowRoomNo),add constraint FK3_sale foreign key (ManufacturerID,SalesPersonID) references SalesPerson (ManufacturerID,PersonID) ;