Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 我可以有一个外键引用两个不同表的主键吗?_Database_Entity Relationship - Fatal编程技术网

Database 我可以有一个外键引用两个不同表的主键吗?

Database 我可以有一个外键引用两个不同表的主键吗?,database,entity-relationship,Database,Entity Relationship,背景信息:客户是一家同时提供房屋维修服务和酒店客房预订服务的公司 以下是我根据需求文件编写的表格: RoomBookingService{ Service_ID(PK) Cost Start_Date End_Date Room_ID } HomeRepairmentService{ Service_ID(PK) Repair_Type Staff_ID date_Of_Repair } Invoice{ Invoice_ID(PK) Service_ID(FK) REFERENCES bo

背景信息:客户是一家同时提供房屋维修服务和酒店客房预订服务的公司

以下是我根据需求文件编写的表格:

RoomBookingService{
Service_ID(PK)
Cost
Start_Date
End_Date
Room_ID
}

HomeRepairmentService{
Service_ID(PK)
Repair_Type
Staff_ID
date_Of_Repair
}

Invoice{
Invoice_ID(PK)
Service_ID(FK) REFERENCES both HomeRepairmentService.Service_ID and RoomBookingService.service_ID
Customer_ID
}

Payment{
Payment_ID(PK)
Invoice_ID
Payment_method
}
如果我错了,有什么解决办法使它正确


另外,我想知道这两种不同的服务是否需要单独的付款和发票表,因为这两种服务本身包含独特的属性。

实现这一点的方法是使用一个
服务
表,其中只有一列,
服务ID
RoomBookingService
HomeRepaimentService
Invoice
都应该将
Service\u ID
作为外键,参考
Service.Service\u ID
表。

您不能对两个表进行外键引用,但是,您可以在
RoomBookingService
HomeRepaiementService
中添加外键,并参考
InDevice
表。你是说我可以使用Service.Service\u ID作为RoomBookingService和HomeRepaimentService的主键?那么,如果我想在例如RoomBookingService中插入一行,SQL查询将是什么呢?您必须将它插入事务中的表
Service
RoomBookingService