Outline

  • Features of Good Relational Design 
  • Functional Dependencies 
  • Decomposition Using Functional Dependencies 
  • Normal Forms 
  • Functional Dependency Theory 
  • Algorithms for Decomposition using Functional Dependencies 
  • Decomposition Using Multivalued Dependencies 
  • More Normal Form 
  • Atomic Domains and First Normal Form  原子域和第一範式
  • Database-Design Process 
  • Modeling Temporal Data

Reference

Ch8 关系数据库设计

Functional Dependencies 函數依賴

Ch8 关系数据库设计

数据库系统原理

Use of Functional Dependencies

Seperate them

Decomposition Using Functional Dependencies

Lossless Decomposition

Ch8 关系数据库设计
We can use functional dependencies to show when certain decomposition are lossless.
image.png
A decomposition of R into R1 and R2 is lossless decomposition if at least one of the following dependencies is in F+ :
image.png

Normal Forms

BCNF - Boyce-Codd Normal Form
语雀内容

23 APR

Closure of Functional Dependencies函数依赖理论

记 A->B 表示 A 函数决定 B,也可以说 B 函数依赖于 A。
如果 {A1,A2,… ,An} 是关系的一个或多个属性的集合,该集合函数决定了关系的其它所有属性并且是最小的,那么该集合就称为键码。
对于 A->B,如果能找到 A 的真子集 A’,使得 A’-> B,那么 A->B 就是部分函数依赖,否则就是完全函数依赖。
对于 A->B,B->C,则 A->C 是一个传递函数依赖。

Procedure for Computing F+

To compute the closure of a set of functional dependencies F:

滚雪球算法

  1. F+ = F
  2. repeat
  3. for each functional dependency f in F+
  4. apply reflexivity and augmentation rules on f
  5. add the resulting functional dependencies to F+
  6. for each pair of functional dependencies f1 and f2 in F+
  7. if f1 and f2 can be combined using transitivity
  8. then add the resulting functional dependency to F+
  9. until F+ does not change any further

(滚雪球求,F+很少用,计算量巨大)

Closure of Attribute Sets

PDF 22
屬性集閉包
将给定依赖集F下被α函数确定的所有属性的集合称为F下α的闭包 α+

判断α是否为超码
通过检查是否 β ⊆ α+,检查 α -> β 是否成立

Canonical Cover正则覆盖 🌟

L07 Normalization - 图3的正则覆盖L07 Normalization - 图4是一个依赖集,使得L07 Normalization - 图5逻辑蕴含L07 Normalization - 图6中的所有依赖,并且L07 Normalization - 图7逻辑蕴含L07 Normalization - 图8中的所有依赖。此外L07 Normalization - 图9必须既有如下性质:

  • L07 Normalization - 图10中任何函数都不含无关属性。
  • L07 Normalization - 图11中函数依赖的左半部都是唯一的。

Computing a Canonical Cover

  1. R = {A,B,C}
  2. 1. "SPLIT"
  3. 2. Remove Extraneous Attributes
  4. 3. Remove Redundant FD
  5. F = {
  6. A > B join C, B > C, A > B, A join B > C
  7. A > B, A > C, B > C, A > B, A join B > C
  8. A > B, A > C, B > C, A join B > C
  9. A > B, A > C, B > C, A > C
  10. A > B (Important) , A > C, B > C
  11. A > B, B > C
  12. }
  13. (A)+ = {A, B, C}
  14. (B)+ = {B, C}

Testing for BCNF (Boyce - Codd Normal Form)

关系模式 R 属于第三范式,且消除了主属性对候选码的部分或传递依赖。

  1. R = (A, B, C, D, E, F)
  2. F = {
  3. A > BCD,
  4. D > EF
  5. }
  6. (A, B, C, D, E, F) += {A, B, C, D, E, F}
  7. (A) += { A, B, C, D, E, F}
  8. (A is Candidate Key)
  9. PRIME ATTRIBUTE = {A}
  10. NOT IN BCNF
  11. - D > EF
  12. (alpha U beta) = {D, E, F}
  13. R - (beta - alpha)
  14. = {A, B, C, D, E, F} - ( {EF} - {D} )
  15. = { A, B, C, D }

BCNF Decomposition Algorithm

  1. R = A B C D E
  2. F = {
  3. A -> B,
  4. BC -> D
  5. }
  6. Superkey -> candidate keys
  7. (ABCDE) += {ABCDE}
  8. (ACE) += {ABCDE}
  9. PRIME ATTRIBUTES = { ACE }
  10. (AC) += {ABCD}
  11. (AE) += {ABE}
  12. (CE) += {CE}
  13. (A) += {AB}
  14. (C) += {C}
  15. (E) += {E}

Canonical Cover

  1. CANONICAL COVER
  2. Fc = {A > B, BC > D}
  3. FC = {A > B, AC > D}
  4. result := {ABCDE}
  5. A > B
  6. result := ((ABCDE) - (AB)) U (AB - B) U (AB))
  7. result := (CDE) U (A) U (AB)
  8. result := (ACDE) U (AB)
  9. AC > D
  10. result := (ACDE)
  11. result := (ACDE) - (ACD) U (ACD - D) U (ACD)
  12. result := (E) U (AC) U (ACD)
  13. result := (ACE) U (ACD) U (AB)
  14. R1(AB): A > B,
  15. R2(ACE),
  16. R3(ACD): AC > D
  1. result = { ABCDE }
  2. BC > D
  3. result := (ABCDE - BCD) U (BCD - D) U (BCD)
  4. result := (AE) U (BC) U (BCD)
  5. result := (ABCE) U (BCD)
  6. A > B
  7. result := ((ABCDE) U (BCD) - (AB)) U (AB - B) U (AB)
  8. result := (BCD) U (CE) U (A) U (AB)
  9. result := (BCD) (ACE) (AB)
  10. BC > D (R1), (R2) (only trivial), A > B (R3)
  11. Dependency - preserving decomposition

Dependency - preserving decomposition

  1. Fc = { A > B, join B > C }
  2. Fc = { A > B, A > C }
  3. R1 = AB, R2 = AC

Primary Key = A,
be sure what is doing

Algorithm of BCNF

Third Normal Form (3NF)

  1. OneTable {
  2. A -> B -> C
  3. }

If I need to do join updated something if I user 3rd Normal Form
Weaker normal form
No candidate key pointing to someone

Fourth Normal Form

First Normal Form

Ch8 关系数据库设计 - 2. 原子域和第一範式

函数依赖/数据依赖 ——> 设计范式 ——> 避免冗余
Ch8 关系数据库设计

Overall Database Design Process

7.89
Assumed Schema R is given

  • Universal relation

ER Model and Normalization

One

Denormalization for Performance

Alternative 1:
Use denormalized relation containing containing attributes of course as well as prereq with all above attributes

Alternative 2:
Materialized view defined a course join prereq

Denormalization Design(反规范化):
形式上,这个术语指的是对基本表结构的修改,这样新的表比原始的表的规范化程度要低。 但也可以用此属于更宽泛地形容将两个表和并成一个新表的情形,而这个新表与原来的表具有相同的范式,但比原表包含 更多的空值。

对不可改变数据的反模式设计。也就是说对不可改变的数据无需模式化设计。例如,用户信息中要记录该用户的国籍,由于国家信息(国家代码、简称都是不可改变的数据或者说改变的机率很小),所以无需在用户信息表中新增列来关联国家信息表,可以直接将相关的国家信息列作为用户信息表中的列。

Other Design Issues

Modeling Temporal Data

时态数据模型

全时态数据模型
本文采用了基于关系数据模型而设计的双时态数据模型。其与普通的关系数据模型主要的区别在于以下两点,一是数据具有状态属性,二是数据具有时态属性。具有这两种属性的数据模型,称为全时态数据模型。

Reference

Ch8 关系数据库设计

Exam Important

  1. Set Closure
  2. Canonical Cover
  3. Candidate Key
  4. Superkey

Final Exam

Final Exam is same as Midterm Exam

  • 3 hours
  • Do it in ummodle