当前位置:网站首页>[easy to understand] relational schema paradigm decomposition tutorial 3NF and BCNF formula! Xiaobai can also understand "suggestions collection"
[easy to understand] relational schema paradigm decomposition tutorial 3NF and BCNF formula! Xiaobai can also understand "suggestions collection"
2022-07-23 18:18:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
It was originally to review the database final exam , As a result, I found no better explanation after looking around , Through consulting materials and summarizing , Provide you with an easy to understand solution , You can hear it ! And equipped with Shorthand formula ! The new version of the ship you haven't played includes minimum dependency set algorithm, candidate code algorithm
Before schema decomposition , First of all, for 1NF,2NF,3NF,BCNF Make a brief introduction .
1NF Each column of a database table is an indivisible basic data item , That is, an attribute in an entity cannot have multiple values or duplicate attributes .
2NF The attribute is required to be completely dependent on the primary key , There cannot be a property that depends only on part of the primary keyword .
3NF Each non primary attribute is required to be neither partially dependent on the code nor transitively dependent on the code .
BCNF It eliminates the dependence of the main attribute on the candidate code and the transfer function .
notes :1. be relative to BCNF,3NF It is allowed to have the transitive dependency and partial dependency of the primary attribute on the candidate code .
2.BCNF More abstract , A little explanation : In the student information form , Student number is a candidate code , The student number can determine the student's name ;( class , The student's name ) It is also a group of candidate codes , Yes ( class , The student's name )-> Student number , Therefore, a transitive dependency is formed between the main attributes .
3. If the concept is not clear , About code 、 Candidate code 、 Main attribute 、 Please refer to :
https://blog.csdn.net/sumaliqinghua/article/details/85872446#commentBox
Our focus is on paradigm decomposition :
One 、3NF decompose
It is divided into maintaining dependency and lossless connection
To illustrate that the solution remains dependent , First, we need to know how to find the minimum dependency set
(1) Minimum dependency set method :
formula : First split the order on the right , Dependencies are deleted in turn .
Restore and delete , Then dismantle the left non single .
Explain the pithy formula by finding the following minimum dependency set ,
(2)3NF decompose :
formula :
Letter of guarantee depends on decomposition , Let's find the minimum dependency set first .
Dependence on both sides does not appear , Divide it into subsets and put it aside , Residual dependent variable set .
To connect without damage , Add candidates for subsets .
Here are some examples to explain the pithy formula :
example 1. It is known that R(ABCDE), F={A ->D,E->D,D->B,BC->D,DC->A} To keep the function dependent 3NF decompose , And with lossless connectivity and functional dependency 3NF decompose
First step : Letter of guarantee depends on decomposition , Let's find the minimum dependency set first . Find out first R The minimum set of dependencies , Available F={A ->D,E->D,D->B,BC->D,DC->A}
The second step : Dependence on both sides does not appear , Divide it into subsets and put it aside . First of all, we can find that there are no elements that do not appear on both sides, and there is no need to separate a subset ,“ Residual dependent variable set ” Then we divide each dependency into subsets to get :{AD} {ED} {DB} {BCD} {DCA}, That is to keep the function dependent 3NF decompose
The third step : To connect without damage , Add candidates for subsets .
(1) Solution of candidate code : The so-called candidate code can determine the whole relationship , We look for Does not appear on the right of dependency And Elements that do not appear on either side You can find ,
(2) You can find C E Not on the right , So the candidate code is {CE}. Therefore, the method has lossless connectivity and function dependence 3NF Decompose into {AD} {ED} {DB} {BCD} {DCA} {CE}
example 2. Relationship model R, Yes U={A,B,C,D,E,G},F={B->G,CE->B,C->A,CE->G,B->D,C->D}, Break down the relationship pattern into 3NF And keep the function dependent
Break down the relationship pattern into 3NF And keep the function dependent :
First step : Letter of guarantee depends on decomposition , Let's find the minimum dependency set first . Find out first R The minimum set of dependencies ,
hypothesis B->G redundancy , be (B)+=BD, No, G So it's not redundant .
hypothesis CE->B redundancy , be (CE)+=CEGDA, No, B So it's not redundant .
hypothesis C->A redundancy , be (C)+=CD, So it's not redundant .
We can get the minimum function dependency set at one time Fm={B->G,CE->B,C->A,B->D,C->D}
The second step : Dependence on both sides does not appear , Divide it into subsets and put it aside , Residual dependent variable set . First of all, it can be found that there are no elements that do not appear on both sides , Then we divide the dependencies into subsets and get {BG} {CEB} {CA} {BD} {CD}, That is to keep the function dependent 3NF decompose
The third step : To connect without damage , Add candidates for subsets . find R A candidate code for is {CE}. Therefore, the method has lossless connectivity and function dependence 3NF Decompose into {BG} {CEB} {CA} {BD} {CD} {CE} ( notes : Paradigm decomposition is not unique , Just be right )
Two 、BCNF decompose :
Model relationships R<U,F> Break down into one BCNF The basic step is
1) Let's find the minimum dependency set first , Waiting codes are not subsets
3) The remaining left side is all waiting , complete BCNF topic .
example . Relationship model R, Yes U={A,B,C,D,E,G},F={B->G,CE->B,C->A,CE->G,B->D,C->D}, Break down the relationship pattern into 3NF And keep the function dependent
Break down the relationship pattern into 3NF And keep the function dependent :
First step : Let's find the minimum dependency set first . You can find CE->G redundant , Therefore, the minimum dependency set is F={B->G,CE->B,C->A,B->D,C->D}.
The second step : Waiting codes are not subsets . Because the candidate code is (CE) So it will CE->B Divide into subsets (BCE), and B->G,B->D There are no primary attributes on the left (C、E) Any one of them is divided into (BG),(BD)
The third step : At this time, the remaining dependencies F={C->A,C->D} The remaining elements {A,C,D} Check and find that the left side of the function dependency is all candidate codes, that is, complete BCNF decompose , If not, continue to decompose the rest .
therefore BCNF The final result of the decomposition is {(BG),(BD),(ACD),(BCE)}.
If you have any questions, please leave a message in the comment area , If you are helpful, please point a like in the upper right corner ~~ Crab
3、 ... and 、 summary
1. Closure
2. Candidate code
3. Minimum dependency set
4.3NF decompose
5.BCNF decompose
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/126601.html Link to the original text :https://javaforall.cn
边栏推荐
- [jzoof] 13 plage de mouvement du robot
- Leetcode: Jianzhi offer II 115. reconstruction sequence [graph theory thinking + in degree consideration + topological sorting]
- 分析一个 .NET 写的 某 RFID标签系统 CPU暴涨
- El input usage
- 【216】go语言标准库包名
- 常用的curl命令及参数详解
- Time frequency domain analysis of 20220721 integral link
- Pessimistic lock and optimistic lock
- 实现多线程的三种方法
- Pdman, a database modeling tool comparable to PowerDesigner [easy to understand]
猜你喜欢

薪资高压线

go语言中的内存对齐是如何优化程序效率的?

Seata

Solutions to sap Hana database backup failure

rhcsa笔记六

Detailed explanation of CO process principle in go

【JZOF】13機器人的運動範圍

rhcsa笔记五

Type-C to OTG (USB2.0 data transmission) + PD charging protocol chip ledrui ldr6028/ldr6023ss

C language -- implementation of address book and screentogif
随机推荐
go语言中的内存对齐是如何优化程序效率的?
多线程编程
如何抓取新浪财经数据中心分析师评级数据?
serialization and deserialization
信息论 (Information Theory): Introduction and information measures
Simply understand why the first EVM equivalent zkevm polygon is fully betting
LDAP unified authentication service solution [easy to understand]
Chi square distribution, analysis of variance
【JZOF】13機器人的運動範圍
awk从入门到入土(16)awk综合案例
Explanation of PPPoE protocol and analysis of Wireshark packet capturing during dialing
传奇架设 GEE引擎教程 配置微端
Problems encountered in the project and Solutions
The loss of training and testing does not decline, and the accuracy is extremely low
Oracle database version after 11C uses memory_ Target automatic memory management
curl get&post
MYSQL基础及性能优化
CSDN定制T恤等你来拿,《新程序员》福利来袭!
How does memory alignment in go optimize program efficiency?
Tencent tore open the "fig leaf" of China's NFT