第三范式(3NF)是資料庫正規化所使用的正規形式,要求所有非主鍵屬性都只和候選鍵有相關性,也就是說非主鍵屬性之間應該是独立無關的。
如果再對第三正規化做進一步加強就成了BC正規形式,強調的重點在於「資料間的關係是奠基在主鍵上、以整個主鍵為考量、而且除了主鍵之外不考慮其他因素」。
正規定義
令:
- {R} 表一個關係;
- F 表維持 R 所需的一組函数依赖;
- X 表 R 屬性的子集合;
- A 表 R 的一個屬性
最早由埃德加·科德在1971年给出的第三范式定义为:
- 关系R(表)满足第二范式 (2NF);
- R的每个非键属性是R的每个候选键的非传递依赖。
Carlo Zaniolo于1982年给出的一个等价定义为:
如果對於 X \to A 這種型式的函数依赖而言,下列敘述任一為真的話,則可以稱 R 符合第三正規化:
- A \in X;也就是說 A 是明顯函数依赖
- X 是超鍵
- A 是 R 的候選鍵的一部份
任何一個具有部份相依性或是轉移相依性的關係都違反了第三正規化。
範例
以下面這個定義機械元件的關係為例:
本例中-{zh;zh-hant;zh-hans|製造商地址}-很明顯地不該被列在這個關係裡面,因為和元件本身比起來,-{zh;zh-hant;zh-hans|製造商地址}-應該和製造商比較有關係;正確的做法應該是把獨立出新的資料表:
然後把原本的資料表改成這樣:
先前那個資料表的問題在於每提到一次製造商名稱就要多存一次它的-{zh;zh-hant;zh-hans|地址}-,而這就不符合第三正規化的原則。
下面提供了另一個例子:
在本例中,非主鍵字段完全依賴于主鍵訂單編號,也就是說唯一的訂單編號能導出唯一非主鍵字段值,符合第二正規化。第三正規化要求非主鍵字段之間不能有依赖關係,顯然本例中小計依赖于非主鍵字段「單價」和「數量」,不符合第三正規化。小計不應該放在這個資料表裡面,只要把單價乘上數量就可以得到小計了;如果想要符合第三正規化的話,就把小計拿掉 (不過在做查詢時, SELECT Order.Total FROM Order 需改成 SELECT UnitPrice * Quantity FROM Order )。
参考文獻
- Ramakrishnan, Raghu and Johannes Gehrke. "Schema Refinement and Normal Forms." Database Management Systems, Third Edition. ISBN 0-07-246563-8. McGraw Hill. August 14, 2002.
- Gupta, Gopal. [https://web.archive.org/web/20070218023436/http://www.cs.jcu.edu.au/Subjects/cp1500/1998/Lecture_Notes/normalisation/3nf.html "Third Normal Form (3NF)."] Single Valued Normalization. 1996.
- [http://www.troubleshooters.com/littstip/ltnorm.html Litt's Tips: Normalization]
- [https://web.archive.org/web/20080805014412/http://www.datamodel.org/NormalizationRules.html Rules Of Data Normalization]
- Date, C. J. (1999), [https://web.archive.org/web/20050404010227/http://www.aw-bc.com/catalog/academic/product/0,1144,0321197844,00.html An Introduction to Database Systems] (8th ed.). Addison-Wesley Longman. ISBN 0-321-19784-4.
- Kent, W. (1983) [http://www.bkent.net/Doc/simple5.htm A Simple Guide to Five Normal Forms in Relational Database Theory] , Communications of the ACM, vol. 26, pp. 120–125
- Date, C.J., & Darwen, H., & Pascal, F. [http://www.dbdebunk.com Database Debunkings]
外部連結
- [http://databases.about.com/od/specificproducts/a/normalization.htm Database Normalization Basics] by Mike Chapple (About.com)
- [https://web.archive.org/web/20110606025027/http://dev.mysql.com/tech-resources/articles/intro-to-normalization.html An Introduction to Database Normalization] by Mike Hillyer.
- [https://web.archive.org/web/20100106115112/http://www.utexas.edu/its/archive/windows/database/datamodeling/rm/rm7.html Normalization] by ITS, University of Texas.
- [https://web.archive.org/web/20110715075109/http://phlonx.com/resources/nf3/ A tutorial on the first 3 normal forms] by Fred Coulson
- [https://web.archive.org/web/20071227154911/http://www.marcrettig.com/poster/ Free PDF poster available] by Marc Rettig
- [http://support.microsoft.com/kb/283878 Description of the database normalization basics] by Microsoft
- [https://web.archive.org/web/20081221084613/http://www.matthew-west.org.uk/documents/princ03.pdf Developing High Quality Data Models]
- [http://www.dama-nj.org/presentations/Kalido_Generic_Data_Modeling.pdf Generic Data Modeling]
- [http://sourceforge.net/projects/gellish The Gellish Language - A Universal Data Structure]
Normalisierung (Datenbank)#Dritte Normalform (3NF)
评论 (0)