可选性(强制性,可选性)和参与性(全部,部分)是否相同? [英] is optionality (mandatory, optional) and participation (total, partial) are same?

查看:303
本文介绍了可选性(强制性,可选性)和参与性(全部,部分)是否相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,可选性是指关系的最小基数,表示为可选对可选,强制对可选,强制对强制。



并且参与表示为粗线和法线。



在Internet中,有些人将参与视为实体对关系的依赖,这也像是识别关系和非识别关系。



,有些人把它称为最小基数



这些关系的正确定义是什么,有什么区别。

解决方案

让我们从每个概念的定义和示例入手:



总计部分参与:



完全参与(用双倍或粗关联线表示)表示实体集中的所有实体都必须参与该关系。部分参与(用一条细线表示)意味着实体集中可以存在不参与关系的实体。





医学完全参与了产品关系,这意味着医学不存在,除非由实验室的生产 。相比之下,实验室可以不使用生产 医学-而存在- 实验室部分参与 Produce 关系ip。



强制性和可选角色:



在关系中,角色可以是可选的或强制的。这会影响在没有给定角色的实体的情况下关系实例是否可以存在。强制角色用实线表示,可选角色用虚线表示。





数据库教程中很少谈论角色,但是它们是一个重要的概念。考虑一下婚姻-具有由同一实体集填充的两个强制性角色的关系。在大多数关系中,实体集也定义角色,但是当实体集在单个关系中出现多次时,我们将它们区分为不同的角色。



以上,患者可以购买 医学有或没有处方。没有患者医学购买就不存在,但处方是可选的(总体,尽管在特定情况下可能需要)。



识别关系/弱实体:



弱实体是无法通过自身属性来标识的实体,因此具有另一个实体的密钥作为它自己的。识别关系是弱实体与其父实体之间的关系。识别关系和弱实体都用双边框表示。弱实体集必须完全参与其标识关系。





在此示例中,处方包含 LineItems ,这些内容由 Prescription标识的键和行号。换句话说, LineItems 表将具有复合键(Prescription_ID,Line_Number)



有关非识别关系的示例,请参见前面的示例。虽然医学完全参与了 Produce 关系,但它具有自己的身份(例如代理密钥,尽管我没有这样做)。 t表示)。请注意,代理键始终暗含常规实体。



强制性/可选性vs全部/部分参与

强制性角色或可选角色指示存在某种关系是否需要特定角色(及其关联的实体集)。全部参与或部分参与表明实体是否存在一定的关系。



强制性部分参与:请参见上文:A 实验室可以不生产任何药物而存在,但是如果没有<$ c $,则医学不能被生产 c>实验室



必须参加的总人数:请参见上方:医学不能存在而没有生产,而实验室不能生产

可选的部分参与:见上文:处方可以存在而不必成为已购买,并且购买可以不带处方而存在。



剩下的可选总参与人数,我不得不考虑一下才能找到一个例子:





某些患者 Die 原因 ,但是没有原因是不存在的>患者 死亡



总参与/部分参与与识别/非识别关系



正如我之前所说,弱实体集始终完全参与其识别关系。参见上文: LineItem 必须在处方中包含在 ,它的身份和存在取决于此。



完全参与并不意味着有确定的关系-医学不能由实验室 生产而不是医学由其自己的属性标识。



部分参与非标识关系非常普遍。例如,医学可以存在而无需购买医学由其自己的属性标识。



强制性/可选vs标识/非标识关系



关系中少于两个强制性角色是不寻常的。标识关系是二进制关系,因此父角色和子角色将是强制性的-处方和<$之间的包含关系c $ c> LineItem 不能同时存在两个实体。



可选角色通常仅在三元或更高关系中才能找到(尽管请参见死于病因的示例),并且不参与识别。可选角色的替代方法是在关系上建立关系:





通过将购买变成一个关联实体,我们可以使其与<$ c $一起参与填充关系c>处方。为了保持与上述相同的语义,我指定了购买只能填充一个 Prescription



物理建模



从概念模型到物理模型(跳过逻辑建模/进一步规范化),为每个实体和关系创建单独的表,尽管您必须知道如何读取外键行的基数指示符以恢复ER语义,但情况看起来非常相似。 / p>



但是,通常对具有相同主表的表进行非规范化键,意味着一对多关系与实体表在许多方面结合在一起:





关系在表中实际表示为两个或多个实体键。在这种情况下,实体键- patient_id cause_of_death_id 都在 Patient 表。许多人认为外键代表关系,但这是因为将实体关系模型与旧的网络数据模型混淆了。



这是关键点-为了理解各种关系以及对关系的约束,必须先了解什么是关系。 ER中的关系是键之间的关联,而不是表之间的关联。关系可以具有不同实体集的任意数量的角色,而外键约束在一个实体集的两列之间强制执行子集约束。现在,有了这些知识,再次阅读我的完整答案。 ;)



我希望这会有所帮助。随时问问题。


As i know optionality means the minimum cardinality of a relationship which is denoted as optional to optional, mandatory to optional, mandatory to mandatory..

And Participation denoted as bold line and a normal line.

In the Internet some refer participation as the dependency of the entity to the relationship which is also looks like identifying and non identifying relationship.

and some refer it as the minimum cardinality

What is the correct definitions of those relationships and what is the difference..

解决方案

Let's start with definitions and examples of each of the concepts:

Total and partial participation:

Total participation (indicated by a double or thick association line) means that all the entities in an entity set must participate in the relationship. Partial participation (indicated by a single thin line) means that there can be entities in the entity set that don't participate in the relationship.

Medicine participates totally in the Produce relationship, meaning that Medicine can't exist unless Produced by a Laboratory. In contrast, a Laboratory can exist without Producing Medicine - Laboratory participates partially in the Produce relationsip.

Mandatory and optional roles:

In a relationship, roles can be optional or mandatory. This affects whether a relationship instance can exist without an entity in a given role. Mandatory roles are indicated with a solid association line, optional roles are indicated with a dotted line.

Roles aren't often talked about in database tutorials, but they're an important concept. Consider a marriage - a relationship with two mandatory roles filled by the same entity set. In most relationships, the entity sets also define the roles, but when an entity set appears multiple times in a single relationship, we distinguish them in different roles.

In the example above, a Patient can Purchase Medicine with or without a Prescription. A Purchase can't exist without a Patient and Medicine, but a Prescription is optional (overall, though it may be required in specific cases).

Identifying relationship / weak entity:

A weak entity is an entity that can't be identified by its own attributes and therefore has another entity's key as part of its own. An identifying relationship is the relationship between a weak entity and its parent entity. Both the identifying relationship and the weak entity are indicated with double borders. Weak entity sets must necessarily participate totally in their identifying relationship.

In this example, a Prescription contains LineItems which are identified by the Prescription's key and a line number. In other words, the LineItems table will have a composite key (Prescription_ID, Line_Number).

For examples of non-identifying relationships, see the previous examples. While Medicine participates totally in the Produce relationship, it has its own identity (e.g. a surrogate key, though I didn't indicate it). Note that surrogate keys always imply regular entities.

Mandatory/optional vs total/partial participation

Mandatory or optional roles indicate whether a certain role (with its associated entity set) is required for the relationship to exist. Total or partial participation indicate whether a certain relationship is required for an entity to exist.

Mandatory partial participation: See above: A Laboratory can exist without producing any medicine, but Medicine can't be Produced without a Laboratory.

Mandatory total participation: See above: Medicine can't exist without being Produced, and a Laboratory can't Produce something unspecified.

Optional partial participation: See above: A Prescription can exist without being Purchased, and a Purchase can exist without a Prescription.

That leaves optional total participation, which I had to think about a bit to find an example:

Some Patients Die of an unknown Cause, but a Cause of death can't exist without a Patient Dying of it.

Total/partial participation vs identifying/non-identifying relationships

As I said before, weak entity sets always participate totally in their identifying relationship. See above: a LineItem must be Contained in a Prescription, it's identity and existence depends on that. Partial participation in an identifying relationship isn't possible.

Total participation doesn't imply an identifying relationship - Medicine can't exist without being Produced by a Laboratory but Medicine is identified by its own attributes.

Partial participation in a non-identifying relationship is very common. For example, Medicine can exist without being Purchased, and Medicine is identified by its own attributes.

Mandatory/optional vs identifying/non-identifying relationships

It's unusual for a relationship to have less than two mandatory roles. Identifying relationships are binary relationships, so the parent and child roles will be mandatory - the Contain relationship between Prescription and LineItem can't exist without both entities.

Optional roles are usually only found on ternary and higher relationships (though see the example of patients dying of causes), and aren't involved in identification. An alternative to an optional role is a relationship on a relationship:

By turning Purchase into an associative entity, we can have it participate in a Fill relationship with Prescription. To maintain the same semantics as above I specified that a Purchase can only Fill one Prescription.

Physical modeling

If we translate from conceptual to physical model (skipping logical modeling / further normalization), making separate tables for each entity and relationship, things look pretty similar, though you have to know how to read the cardinality indicators on the foreign key lines to recover the ER semantics.

However, it's common to denormalize tables with the same primary keys, meaning one-to-many relationships are combined with the entity table on the many side:

A relationship is physically represented as two or more entity keys in a table. In this case, the entity keys - patient_id and cause_of_death_id are both found in the Patient table. Many people think the foreign key line represents the relationship, but this comes from confusing the entity-relationship model with the old network data model.

This is a crucial point - in order to understand different kinds of relationships and constraints on relationships, it's essential to understand what relationships are first. Relationships in ER are associations between keys, not between tables. A relationship can have any number of roles of different entity sets, while foreign key constraints enforce a subset constraint between two columns of one entity set. Now, armed with this knowledge, read my whole answer again. ;)

I hope this helps. Feel free to ask questions.

这篇关于可选性(强制性,可选性)和参与性(全部,部分)是否相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆