database 部分依赖(数据库)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25747802/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 07:48:38  来源:igfitidea点击:

Partial Dependency(Databases)

databasefunctional-dependencies

提问by rert588

I need closure on this. I fabricated a definition that partial dependency is when fields are indirectly dependent on the primary key or partially dependent but are also dependent on other keys that depend on the primary such that if the field which another field depends on id deleted that field will still exist due to its dependence on the primary key. I am not sure if it is correct. I have researched and every definition sounds misleading.Is my definition correct and if not please explain?

我需要就此结束。我捏造了一个定义,即部分依赖是当字段间接依赖于主键或部分依赖但也依赖于依赖于主键的其他键时,如果另一个字段依赖于 id 的字段被删除,该字段仍将存在到它对主键的依赖。我不确定它是否正确。我已经研究过,每个定义听起来都有误导性。我的定义是否正确,如果不正确,请解释一下?

回答by philipxy

A FD (functional dependency) that holds in a relation is partial when removing one of the determining attributes gives a FD that holds in the relation. A FD that isn't partial is full.

当移除确定属性之一给出在关系中成立的 FD 时,在关系中成立的 FD(函数依赖)是部分的。非部分的 FD 是满的。

Eg: If {A,B} → {C} but also {A} → {C} then {C} is partially functionally dependent on {A,B}.

例如:如果 {A,B} → {C} 并且 {A} → {C} 则 {C} 在功能上部分依赖于 {A,B}。

Eg: Here's a relation value where that example condition holds. (A FD holds in a relation variable when it holds in every value that can arise.)

例如:这是该示例条件成立的关系值。(当 FD 保存在每个可能出现的值中时,它也保存在关系变量中。)

A  B  C
1  1  1
1  2  1
2  1  1

The non-trivial FDs that hold: {A,B} determines {C}, {B,C}, {A,C} & {A,B,C}; {A}, {B} & {} also determine {C}. Of those: {A,B} → {C} is partial per {A} → {C}, {B} → {C} & {} → {C}; {A} → {C} & {B} → {C} are partial per {} → {C}; the others are full.

持有的非平凡 FD:{A,B} 决定 {C}、{B,C}、{A,C} 和 {A,B,C};{A}、{B} 和 {} 也决定了 {C}。其中:{A,B} → {C} 是部分 {A} → {C},{B} → {C} & {} → {C};{A} → {C} & {B} → {C} 是部分 {} → {C};其他都满了。

A functional dependency X → Y is a full functional dependency if removal of any attribute A from X means that the dependency does not hold any more; that is, for any attribute A ε X, (X – {A}) does not functionally determine Y. A functional dependency X → Y is a partial dependency if some attribute A ε X can be removed from X and the dependency still holds; that is, for some A ε X, (X – {A}) → Y.

-- FUNDAMENTALS OF Database Systems SIXTH EDITION Ramez Elmasri & Navathe

如果从 X 中删除任何属性 A 意味着依赖不再成立,则函数依赖 X → Y 是全函数依赖;也就是说,对于任何属性 A ε X,(X – {A}) 不能在功能上确定 Y。如果可以从 X 中删除某些属性 A ε X 并且依赖仍然成立,则函数依赖 X → Y 是部分依赖;也就是说,对于某些 A ε X,(X – {A}) → Y。

-- 数据库系统基础第六版 Ramez Elmasri & Navathe

Notice that whether a FD is full vs partial doesn't depend on CKs (candidate keys), let alone one CK that you might be calling the PK (primary key).

请注意,FD 是完整还是部分不取决于 CK(候选密钥),更不用说您可能将其称为 PK(主密钥)的 CK。

(A definition of 2NF is that every non-CK attribute is fully functionally determined by every CK. Observe that the only CK is {A,B} & the only non-CK attribute C is partially dependent on it so this value is not in 2NF & indeed it is the lossless join of components/projections onto {A,B} & {A,C}, onto {A,B} & {B,C} & onto {A,B} & {C}.)

(2NF 的定义是每个非 CK 属性在功能上完全由每个 CK 决定。观察到唯一的 CK 是 {A,B} 并且唯一的非 CK 属性 C 部分依赖于它,因此该值不在2NF & 实际上它是组件/投影到 {A,B} & {A,C}、{A,B} & {B,C} & {A,B} & {C} 上的无损连接。)

(Beware that that textbook's definition of "transitive FD" does notdefine the same sort of thing as the standard definition of "transitive FD".)

(要注意的是“传递FD”那教科书的定义并没有定义相同的排序为“传递FD”的标准定义的东西。)

回答by Mike Sherrill 'Cat Recall'

Partial dependencymeans that a nonprime attribute is functionally dependent on partof a candidate key. (A nonprime attribute is an attribute that's not part of anycandidate key.)

部分依赖意味着非主要属性在功能上依赖于候选键的一部分。(非主要属性是不属于任何候选键的属性。)

For example, let's start with R{ABCD}, and the functional dependencies AB->CD and A->C.

例如,让我们从 R{ABCD} 开始,以及函数依赖关系 AB->CD 和 A->C。

The only candidate key for R is AB. C and D are a nonprime attributes. C is functionally dependent on A. A is partof a candidate key. That'sa partial dependency.

R 的唯一候选键是 AB。C 和 D 是非素数属性。C 在功能上依赖于 A。A 是候选键的一部分是部分依赖。

回答by rashedcs

Partial Dependencyis one kind of functional dependency that occur when primary key must be candidate key and non prime attribute are depends on the subset/part of candidates key (more than one primary key).

部分依赖是一种函数依赖,当主键必须是候选键并且非主属性依赖于候选键的子集/部分(多个主键)时发生。

Try to understand partial dependency relate through example :

尝试通过示例了解部分依赖关系:

Seller(Id, Product, Price)

卖家(ID,产品,价格)

Candidate Key :Id, Product
Non prime attribute :Price

候选键:Id,产品
非主要属性:价格

Price attribute only depends on only Product attributewhich is a subset of candidate key, Not the whole candidate key(Id, Product) key. It is called partial dependency.

Price 属性仅取决于 Product 属性,它是候选键的子集,而不是整个候选键 (Id, Product) key。它被称为部分依赖。

So we can say that Product->Priceis partial dependency.

所以我们可以说Product->Price是部分依赖。

回答by Lehlohonolo

Partial dependencyimplies is a situation where a non-prime attribute(An attribute that does not form part of the determinant(Primary key/Candidate key)) is functionally dependentto a portion/part of a primary key/Candidate key.

部分依赖意味着非主属性(不构成行列式(主键/候选键)的一部分的属性)在功能上依赖于主键/候选键的一部分/部分的情况。

回答by Juhi Shelar

Partial Functional Dependencyoccurs only in relation with composite keys. Partial functional dependency occurs when one or more non key attribute are depending on a part of the primary key.

部分功能依赖仅与复合键有关。当一个或多个非键属性依赖于主键的一部分时,就会出现部分功能依赖。

Example:

例子:

Table: Stud_id, Course_id, Stud_name, Course_Name

表:Stud_id、Course_id、Stud_name、Course_Name

Where: Primary Key = Stud_id + Course_id

其中:主键 = Stud_id + Course_id

Then: To determine name of student we use only Stud_id, which is part of primary key.

然后:为了确定学生的姓名,我们只使用 Stud_id,它是主键的一部分。

{Stud_id} -> {Stud_Name}

{Stud_id} -> {Stud_Name}

Hence,Stud_name is partially dependent on Stud_id. This is called partial dependency.

因此,Stud_name 部分依赖于 Stud_id。这称为部分依赖。

回答by Vincent Lam

I hope this explaination gives a more intuitive appeal to dependency than the answers previously given.

我希望这个解释比之前给出的答案更直观地吸引依赖。

Functional Dependency

功能依赖

An analysis of dependency operates on the attribute level, i.e. one or more attribute is determined by another attribute, it comes before the concept of keys. 'The role of a key is based on the concept of determination. 'Determination is the state in which knowing the value of one attribute makes it possible to determine the value of another.' Database Systems 12ed

依赖分析是在属性层面上进行的,即一个或多个属性由另一个属性决定,它出现在键的概念之前。'钥匙的作用是基于确定的概念。“确定是一种状态,在这种状态下,知道一个属性的值可以确定另一个属性的值。” 数据库系统 12ed

Functional dependency is when one or more attributes determine one or more attributes. For instance:

功能依赖是当一个或多个属性决定一个或多个属性时。例如:

Social Security Number -> First Name, Last Name.

社会安全号码 -> 名字,姓氏。

However, by definition of functional dependency:

但是,根据函数依赖的定义:

(SSN, First Name) -> Last Name

(SSN,名字)-> 姓氏

This is also a valid functional dependency. The determinants(The attribute that which determines another attribution) are called super key.

这也是一个有效的函数依赖。的决定因素(的属性,该属性,它确定另一归属)被称为超级键

Full Functional Dependency

全功能依赖

Thus, as a subset of functional dependency, there is the concept of full functional dependency, where the bare minimal determinant is considered. We refer those bare minimal determinants collectively as one candidate key(weird linguistic quirk in my opinion, like the concept of vector).

因此,作为函数依赖的一个子集,有全函数依赖的概念,其中考虑了最小的行列式。我们将那些最小的决定因素统称为一个候选键(在我看来,这是一种奇怪的语言怪癖,就像向量的概念一样)。

Partial Functional Dependency

部分功能依赖

However, sometimes one of the attributes in the candidate key is sufficient to determine another attribute(s), BUT not all, in a relation (a table with no rows). That, is when you have a partial functional dependency within a relation.

然而,有时候选键中的一个属性足以确定关系(没有行的表)中的另一个属性,但不是全部。也就是说,当您在关系中具有部分功能依赖时。

回答by EnriqueVillar

Partial dependence is solved for arriving to a relation in 2NF but 2NF is a "stepping stone" (C. Date) for solving any transitive dependency and arriving to a relation in 3NF (which is the operational target). However, the most interested thing on partial dependence is that it is a particular case of the own transitive dependency. This was demostrated by P. A. Berstein in 1976: IF {(x?y)→z but y→z} THEN {(x?y)→y & y→z}. The 3NF synthesizer algorithm of Berstein does not need doing distintions among these two type of relational defects.

部分依赖是为了到达 2NF 中的关系而解决的,但 2NF 是解决任何传递依赖并到达 3NF 中的关系(这是操作目标)的“垫脚石”(C.Date)。然而,对部分依赖最感兴趣的是它是自身传递依赖的一个特例。PA Berstein 在 1976 年证明了这一点:IF {(x?y)→z but y→z} THEN {(x?y)→y & y→z}。Berstein的3NF合成器算法不需要区分这两种关系缺陷。

回答by sagar

If there is a Relation R(ABC)

如果存在关系 R(ABC)

-----------
|A | B | C |
-----------
|a | 1 | x |
|b | 1 | x |
|c | 1 | x |
|d | 2 | y |
|e | 2 | y |
|f | 3 | z |
|g | 3 | z |
 ----------
Given,
F1: A --> B 
F2: B --> C

The Primary Key and Candidate Key is: A

主键和候选键是:A

As the closure of A+ = {ABC} or R --- So only attribute A is sufficient to find Relation R.

由于 A+ = {ABC} 或 R 的闭包 --- 所以只有属性 A 足以找到关系 R。

DEF-1:From Some Definitions (unknown source) - A partial dependency is a dependency when prime attribute (i.e., an attribute that is a part(or proper subset) of Candidate Key) determines non-prime attribute (i.e., an attribute that is not the part (or subset) of Candidate Key).

DEF-1:From Some Definitions (unknown source) - 部分依赖是当主要属性(即,作为候选键的一部分(或适当子集)的属性)确定非主要属性(即,不是候选键的一部分(或子集))。

Hence, A is a prime(P) attribute and B, C are non-prime(NP) attributes.

因此,A 是素数(P)属性,而 B、C 是非素数(NP)属性。

So, from the above DEF-1,

所以,从上面的DEF-1

CONSIDERATION-1:: F1: A --> B (P determines NP) --- It must be Partial Dependency.

CONSIDERATION-1:: F1: A --> B (P 决定 NP) --- 它必须是部分依赖。

CONSIDERATION-2:: F2: B --> C (NP determines NP) --- Transitive Dependency.

CONSIDERATION-2:: F2: B --> C (NP 决定 NP) --- 传递依赖。

What I understood from @philipxy answer (https://stackoverflow.com/a/25827210/6009502) is...

我从@philipxy 的回答(https://stackoverflow.com/a/25827210/6009502)中了解到的是......

CONSIDERATION-1:: F1: A --> B; Should be fully functional dependency because B is completely dependent on A and If we Remove A then there is no proper subset of (for complete clarification consider L.H.S. as X NOT BY SINGLE ATTRIBUTE) that could determine B.

考虑-1:: F1: A --> B; 应该是完全函数依赖,因为 B 完全依赖于 A,如果我们删除 A,那么没有适当的子集(为了完整的说明,将 LHS 视为 X NOT BY SINGLE ATTRIBUTE)可以确定 B。

For Example: If I consider F1: X --> Y where X = {A} and Y = {B} then if we remove A from X; i.e., X - {A} = {}; and an empty set is not considered generally (or not at all) to define functional dependency. So, there is no proper subset of X that could hold the dependency F1: X --> Y; Hence, it is fully functional dependency.

例如:如果我考虑 F1: X --> Y where X = {A} and Y = {B} 那么如果我们从 X 中删除 A; 即,X - {A} = {}; 并且通常不考虑(或根本不考虑)空集来定义功能依赖。所以,没有 X 的真子集可以保存依赖 F1: X --> Y; 因此,它是完全函数依赖。

F1: A --> B If we remove A then there is no attribute that could hold functional dependency F1. Hence, F1 is fully functional dependency not partial dependency.

F1: A --> B 如果我们删除 A 则没有属性可以保存函数依赖 F1。因此,F1 是完全函数依赖而不是部分依赖。

If F1 were, F1: AC --> B;
and F2 were, F2: C --> B; 
then on the removal of A;
C --> B that means B is still dependent on C; 
we can say F1 is partial dependecy.

So, @philipxy answer contradicts DEF-1 and CONSIDERATION-1 that is trueand crystal clear.

因此,@philipxy 的回答与真实且清晰的DEF-1 和 CONSIDERATION-1 相矛盾

Hence, F1: A --> B is Fully Functional Dependency not partial dependency.

因此, F1: A --> B 是完全功能依赖而不是部分依赖。

I have considered X to show left hand side of functional dependency because single attribute couldn't have a proper subset of attributes. Here, I am considering X as a set of attributes and in current scenario X is {A}

我已经考虑 X 显示函数依赖的左侧,因为单个属性不能有一个适当的属性子集。在这里,我将 X 视为一组属性,在当前场景中 X 是 {A}

-- For the source of DEF-1, please search on google you may be able to hit similar definitions. (Consider that DEF-1 is incorrect or do not work in the above-mentioned example).

-- DEF-1的来源,请在谷歌上搜索你可能会找到类似的定义。(考虑 DEF-1 不正确或在上述示例中不起作用)。

回答by Yash Zade

  • consider a table={cid,sid,location}
  • candidate key: cidsid (uniquely identify the row)
  • prime attributes: cid and sid (attributes which are used in making of candidate key)
  • non-prime attribute: location(attribute other than candidate key)
  • 考虑一个表={cid,sid,location}
  • 候选键:cidsid(唯一标识行)
  • 主要属性:cid 和 sid(用于制作候选键的属性)
  • 非主属性:位置(候选键以外的属性)

if candidate key determine non-prime attribute:

如果候选键确定非主属性:

i.e cidsid--->location (---->=determining) 
   then, it is fully functional dependent

if proper subset of candidate key determining non-prime attribute:

if 确定非主属性的候选键的真子集:

 i.e sid--->location (proper subset are sid and cid)
         then it is term as partial dependency

to remove partial dependency we divide the table accordingly .

为了消除部分依赖,我们相应地划分表格。