What's the relationship between the two entities?

丶灬走出姿态 提交于 2019-12-24 09:08:02

问题


The ER diagram for a database is given below:

Now, what's the relationship between planes and flights entities?

I'd say one to many, but that'd be wrong because while one plane can have more than one flights, many flights can't have one (single) plane simultaneously.

So, what exactly is the relationship?

I'm new to databases. Please tell me if I'm wrong.


回答1:


First, your diagram isn't an ER diagram, it's a table diagram. ER diagrams must be able to represent the ER model, which supports ternary and higher relationships, weak entity sets and identifying relationships, and other concepts for which table diagrams don't have notation. Proper ER diagram notation is generally referred to as Chen's notation.

Now, ER relationships are easily identified by looking for entity domains (columns that identify entity sets) that appear in the same table. These are usually indicated by PK and/or FK, but they need not be.

When you have a binary relationship (two entity domains in the same table), look at the unique constraints on these domains:

  • One-to-one relationships require two separate unique constraints, one for each domain.

  • One-to-many relationships require a unique constraint on the domain on the many side.

  • Many-to-many relationships require a composite unique constraint on both domains together.

One-to-many relationships can be denormalized into the entity relation of the entity on the many side, since the unique constraint required for the relationship matches the PK for the entity relation. One-to-one relationships can be denormalized into either entity relation. A many-to-many relationship requires a composite key, and must be represented as a separate relation since the composite key doesn't match either entity relation's PK.

In your example, (flight_num, planeID) represents the relationship, and since only flight_num is uniquely constrained (due to being the PK of the flights relation), this is a many-to-one relationship: each flight is associated with exactly one plane, while each plane can be involved in many flights.

Here's a visual reference in which unique constraints are indicated with underlining:

Many people still use terminology and concepts from the old network data model, such as conflating relationships with FK constraints and entity sets with tables (which is why table diagrams are often mistakenly called ERDs). I highly recommend reading Codd's paper "A Relational Model of Data for Large Shared Data Banks" and Chen's paper "The Entity-Relationship Model - Toward a Unified View of Data".




回答2:


As you said the relation is One-To-Many because if it is a Many-To-Many relation it must have a junction table between these 2 tables (Tbl_Plane_Flight) , another thing is that Plane_Id is referenced in Flights table.

But there must be a validation rule (or a constraint in flights table) for this relation, that a plane cannot have many flight as the same time



来源:https://stackoverflow.com/questions/42712751/whats-the-relationship-between-the-two-entities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!