简体   繁体   English

同一张表之间可以有两个一对一的关系吗?

[英]Can there be two one-to-one relationships between the same tables?

Can there be two one-to-one relationships between the same tables?同一张表之间可以有两个一对一的关系吗? And is it actually a "right" way to represent this?它实际上是一种“正确”的表示方式吗?

The task for such entities in the publication office database is following:出版办公室数据库中此类实体的任务如下:

Each order is assigned a unique number, customer id, type of printed material, publication , printing house, order acceptance date, order completion date, and print quality.每个订单都分配有唯一编号、客户 ID、印刷材料类型、出版物、印刷厂、订单接受日期、订单完成日期和印刷质量。 Information about publications includes: publication code, author(s), title of publication, volume in printed sheets, circulation (number of copies), unique order number .有关出版物的信息包括:出版物代码、作者、出版物名称、印张数量、发行量(份数)、唯一订单号

So to have the attributes publication and order number (in bold) in each table, I have to create two one-to-one relationships:因此,要在每个表中包含属性发布和订单号(粗体),我必须创建两个一对一关系:

数据库

That wouldn't work because initially, you wouldn't be able to add anything to the Order or Publication table without violating the FK constraint.这是行不通的,因为最初,您无法在不违反 FK 约束的情况下向 Order 或 Publication 表添加任何内容。 You would be better off combining the Order and Publication tables into a single table with a composite primary key of orderId and publicationId.您最好将 Order 和 Publication 表组合成一个具有 orderId 和 publicationId 复合主键的表。 This would correctly express the fact that a given order and publication pairing is unique.这将正确地表达给定顺序和发布配对是唯一的这一事实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM