数据库范式分解

Superkey,Minimal key,Primary key和Candidate key

A superkey is a nonempty subset X of relational schema R = (A1 , … , An ) such that for any two rows t1 , t 2in a relational table created over a relational schema R t 1[X] ≠ t2 [X]
简而言之,如果X是R的一个超键,那么X→ A1 , … , An.

A minimal key is a superkey K with an additional property such that removal of any attribute from K will cause K not to be a superkey
最小键是超键的子集,它比起超键有一个附加条件就是如果在超键中删除任何一个属性就会导致它不再是超键。

例如,一个关系模式:DRIVER(licence#, employee#, first-name, last-name)
有两个最小键(licence#) and (employee#)
但是它可以有很多个超键
==(licence#) ,(employee#) , (licence#, employee#) , (licence#, first-name), (licence#, last-name) , (licence#, first-name, last-name)==等等。

A primary key is an arbitrarily selected minimal key.
A candidate key is any other minimal key which is not a primary key.
举例:
DRIVER(licence#, employee#, first-name, last-name)
has a primary key (licence#) and a candidate key (employee#) 或者反过来也成立。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

Attributes

属性
A prime attribute is an attribute from relational schema R which is a member of at least one candidate key in R.
A nonprime attribute is an attribute which is not prime.

举例而言,
licence# and employee# are prime attributes in a relational schema.
DRIVER(licence#, employee#, first-name, last-name)
而first-name and last-name are nonprime attributes in a relational schema.

Full and partial functional dependencies

完全和部分函数依赖关系
如果存在一个完全依赖函数X→Y,在X中删除任何属性都会导致X无法→Y

部分函数依赖为 不是完全函数依赖的函数依赖。

ENROLMENT(student#, subject#, edate, grade)
student#, subject#, edate →grade是完全依赖函数因为不能从函数依赖项的左侧删除任何属性student#、subject#、date,使其仍然有效。

DRIVER(licence#, employee#, first-name, last-name)

licence#, employee# →first-name, last-name 是部分函数依赖,因为 licence#或employee# 两者删除任何一个属性都会是函数依然成立,因为 licence#和employee# 都是最小键。

0NT & 1NF

在这里插入图片描述
1NF: A relational table that has no multivalued attributes and composite attributes
没有多值属性和复合属性的关系表

2NF

在这里插入图片描述
如果R中的每个nonprime属性A在功能上完全依赖于模式R的主键,那么关系模式R就属于第二范式(2NF)。

Example

在这里插入图片描述
在这里插入图片描述

INVENTORY(part, quantity, warehouse,warehouse address)

warehouse → warehouse-address
part, warehouse → quantity

通过依赖关系变换,我们得到
part, warehouse → warehouse-address, quantity
它在INVENTORY中是有效的,并且覆盖了整个关系模式的所有属性,因此它的左手边是一个最小键(part, warehouse)

因此关系模式
INVENTORY(part, quantity, warehouse,warehouse address) 不是在2NF因为 nonprime属性warehouse-address 依赖于部分主键(part, warehouse)中的
// warehouse → warehouse-address.

如果关系模式中的所有最小键只包含一个属性(单个属性键),那么这样的模式总是在2NF中。
这是因为架构中的任何非主属性都不依赖于键的一部分(因为每个键都包含
只有一个属性!

把不满足2NF的范式分解为2NF

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

3NF

回顾传递函数依赖

在这里插入图片描述

3NF定义

如果关系模式R属于2NF,并且R的nonprime属性没有传递依赖于主键,那么它就属于第三范式(3NF)。
Relational schema R is in 3NF if it is in 2NF and no nonprime attribute of R is transitively dependent on the primary key

Example

在这里插入图片描述

在这里插入图片描述

把不满足3NF的范式分解为3NF

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
一个zip-code可以唯一确定一个city
但是city不能唯一确定zip-code

BCNF

假设函数依赖项都在X→A在R中有效,并且无论何时都满足X是R的超键,那么关系模式R就是Boyce-Codd范式(BCNF)。
在这里插入图片描述

Example

在这里插入图片描述

把不满足BCNF的范式分解为BCNF

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

至多包含两个属性的关系架构满足?NF

Every relational schema, which consists of at most 2 attributes is always in BCNF、3NF、2NF、1NF。

进行范式分解的步骤

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
非主属性city不是完全函数依赖于(s#,p#),因为删除p#后仍然有s#→city
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
也可以这么分解
在这里插入图片描述

另一种方法:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

总结

NF定义记忆点
1NFA relational table that has no multivalued attributes and composite attributes不能有嵌套属性
2NFEvery nonprime attribute A in R is fully functionally dependent on a primary key of schema R要完全依赖
3NFIt is in 2NF and no nonprime attribute of R is transitively dependent on the primary key不能有传递依赖
BCNFA relational schema R is in BCNF if whenever functional dependency x →A holds in R then X is a superkey in RFD的左侧要是超键
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值