简体   繁体   English

为什么在3NF中使用此表?

[英]Why is this table in 3NF?

Consider the following table: 请考虑下表:

在此处输入图片说明

The primary key is a composite key consisting of PatID and PhysName. 主键是由PatID和PhysName组成的复合键。 My professor says this table is in 3rd normal form. 我的教授说这张桌子是第三普通形式。 I thought it's not even in second normal form because the non-key attribute, Name, is not dependent on the entire primary key. 我以为它甚至都不是第二范式,因为非键属性Name不依赖于整个主键。 You can identify the Name simply by looking at PatID. 您只需查看PatID即可识别名称。 It is not dependent on PhysName. 它不依赖于PhysName。

In order to really know whether the table is in 2NF or not, you would have to have the functional dependencies explicitly laid out for you. 为了真正知道该表是否在2NF中,您必须具有明确为您设计的功能依赖项。

Inferring the FDs from a small sample of data is a risky business. 从少量数据中推断出FD是一项冒险的业务。 The smaller the sample, the greater the risk. 样品越小,风险越大。

We would have to see a patient with two physicians here to see whether the name is the same. 我们将不得不在这里看到有两位医生的病人,以查看名称是否相同。 I expect it would be, but that's only common sense. 我希望是这样,但这只是常识。

When you move on from classroom exercises to million dollar projects, you'll find that common sense is an unreliable substitute for data analysis. 当您从课堂练习转到数百万美元的项目时,您会发现常识是数据分析的不可靠替代品。

Given a table value we can see what FDs (functional dependencies) hold in it, hence what its CKs (candidate keys) are and what NFs (normal forms) it satisfies (up to BCNF). 给定一个表值,我们可以看到其中包含什么FD(功能依赖项),因此可以看到它的CK(候选键)以及它满足的NF(标准形式)(不超过BCNF)。 (We can't know the CKs & NFs without knowing the FDs.) (我们不知道FD就无法知道CK和NF。)

A FD (or any constraint) holds in a variable when it holds in every value that can arise . 当FD(或任何约束)包含所有可能出现的值时,它就会包含在变量中。 Then its CKs and satisfied NFs are based on those FDs. 然后,其CK和满意的NF基于这些FD。 So for a variable, example data tells us that certain FDs don't hold, and the "trivial" FDs must hold, but for the other FDs example data just doesn't tell us whether they hold. 因此,对于一个变量,示例数据告诉我们某些FD 成立,而“琐碎”的FD 必须成立,但对于其他FD,示例数据只是不告诉我们它们是否成立。

Since the table value doesn't have {PatId, PhysName} as CK, your instructor must mean that that some variable with that value has that CK. 由于表没有{PatId,PhysName}作为CK,因此您的讲师必须表示具有该值的某个变量具有该CK。 (Of course, you should have got value vs variable straight anyway.) In order to consider that that variable has that CK, they must have decided something like: (当然,无论如何,您都应该直接获得值与变量。)为了考虑该变量具有该CK,他们必须确定以下内容:

  • the table holds rows that make a true statement from "a physician named PhysName tends a patient they identify as PatId and know by name PatName " 该表中包含以下行,这些行来自“名叫PhysName的医生抚养了一个他们被识别为PatId并通过名字PatName知道的患者
  • the physicians with a given name each only knows their patients with a given id by one name 具有给定名称的医师每个只通过一个名称知道具有给定ID的患者
  • (we don't know that it's false that) two different physicians could identify two different patients by the same id (我们不知道这是错误的)两个不同的医生可以通过相同的ID来识别两个不同的患者
  • likely that each physician has a unique name 每个医师都有一个唯一的名字
  • likely that each physician identifies every one of their patients by an id 每个医师可能通过ID识别其每个患者
  • likely that a physician identifies just one patient via a given id 医师可能通过给定的ID识别出一名患者
  • likely that a physician identifies a patient via only one id 医生可能仅通过一个ID来识别患者
  • likely that "identifies" always means a 1:1 correspondence of entities & ids “识别”可能始终表示实体和ID的1:1对应
  • likely that each patient has only one name 每个病人可能只有一个名字
  • etc 等等

You need to know whether it's value vs variable, and it's pointless to argue about a variable and constraints (including FDs) until you agree on the predicate and the BRs (Business rules). 您需要知道它是值还是变量,争论变量和约束(包括FD)毫无意义,直到您对谓词和BR(业务规则)达成一致。


PS Re BRs, predicates & constraints: PS Re BR,谓词和约束:

A proposition is a statement about a situation: "a physician named 'Scholl, F.' 命题是关于一种情况的陈述:“名叫'Scholl,F.'的医生。 tends a patient they identify as 99999 and know by name 'Gore, Z.'". 照看他们识别为99999并以名字'Gore,Z.'认识的患者。” A predicate is a statement template mapping from a row of column names & values to a proposition: "a physician named PhysName tends a patient they identify as PatId and know by name PatName ". 谓词是从行名称和值行到命题的语句模板:“名叫PhysName的医师会抚养他们识别为PatId并以名字PatName认识的患者 ”。 A table variable holds the rows that form true propositions in a situation. 变量保存在某种情况下构成真实命题的行。

BRs ( business rules ) give variable predicates and characterize what situations can arise. BR业务规则 )给出可变的谓词,并描述可能出现的情况。 Hence what table variable values can arise, hence what FDs hold, hence the CKs, etc. 因此,可以出现哪些表变量值,因此可以容纳哪些FD,从而可以容纳CK等。

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

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