COMP9311 Database Systems WEEK9

1. Relational Design Theory

1.1 Relation model introduction

在ER model之外,最流行的數(shù)據(jù)模型是relation model,它大大簡(jiǎn)化了傳統(tǒng)網(wǎng)絡(luò)模型/層次模型的coding工作量。同時(shí)能夠評(píng)估schema的優(yōu)劣,使得數(shù)據(jù)存儲(chǔ)更加簡(jiǎn)潔,關(guān)系更加清晰。

一個(gè)好的database應(yīng)該使用最小的存儲(chǔ)空間體現(xiàn)所有的必要attributes,規(guī)避數(shù)據(jù)冗余。數(shù)據(jù)冗余最直接的弊端就是難以操作數(shù)據(jù)庫(kù),任何一個(gè)點(diǎn)的數(shù)據(jù)update,都要找到所有重復(fù)該數(shù)據(jù)的位置進(jìn)行更新。所以database的design要盡可能減少tables之間的overlap,同時(shí)一個(gè)table實(shí)現(xiàn)一個(gè)功能,不要復(fù)合在一起。通常一個(gè)table只能含有一個(gè)entity。
相比于ER model,relation model能夠保證minimal redundancy,它可以深入到non-key的relation進(jìn)行設(shè)計(jì),但是ER model做不到。

1.2 Notation/Terminology

Relation schemas: upper-case letters, denoting set of all attributes (e.g. R, S, P, Q )
Relation instances: lower-case letter corresponding to schema (e.g. r(R), s(S), p(P), q(Q) )
Tuples: lower-case letters (e.g. t, t', t1, u, v )
Attributes: upper-case letters from start of alphabet (e.g. A, B, C, D )
Sets of attributes: simple concatenation of attribute names (e.g. X=ABCD, Y=EFG )
Attributes in tuples: tuple[attrSet] (e.g. t[ABCD], t[X])

重要概念:functional dependencies are constraints between attributes within a relation.
A relation instance r(R) satisfies a dependency X → Y if
--for any t,u ∈ r, t[X]=u[X] → t[Y]=u[Y]
Y is functionally dependent on X, OR X determines Y
schema-based dependency:
--for any t, u ∈ any r(R), t[X] = u[X] → t[Y] = u[Y]

Inference Rules:
-Reflexivity, X -> X
-Augmentation, X -> Y --> XZ -> YZ
-Transitivity, X -> Y, Y -> Z --> X -> Z
-Additivity, X -> Y, X -> Z --> X -> YZ
-Projectivity, X -> YZ --> X -> Y, X -> Z
-Pseudotransitivity, X -> Y, YZ -> W --> XZ -> W

重要概念:Closures - The largest collection of dependencies that can be derived from F is called the closure of F and is denoted F+.

1.3 Normalization

Normalization是為了減少data/relation redundancy。共有6個(gè)normal forms(NF): 1NF, 2NF, 3NF, BCNF, 4NF, 5NF,前述順序是redundancy從大到小。
(1)1NF
要求所有的attribute都是atomic的,所以任何composite的attribute都要把最細(xì)節(jié)的信息當(dāng)做attribute,比如name中必須把所有first, middle, last放在attribute中,不能放入一個(gè)name作為attribute,而實(shí)際上name又分為first, middle, last。
(2)2NF
所有的非primary key都要完全depend on primary key,沒有partial dependencies。
(3)3NF
所有的non-key attributes不能determine other non-key attributes。
(4)BCNF
所有的non-key attributes不能反過來決定primary key。
4NF和5NF極少使用,因?yàn)閞edundancy的減少往往要以犧牲performance為代價(jià),最常用的是3NF和BCNF。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容