关系规范化中的4个问题
1:数据冗余:比如,每一个系的系主任姓名重复出现,重复次数与该系所有学生的所有课程成绩出现次数相同。这将浪费很大的存储空间。
2:更新异常:由于数据冗余,当更新数据库中的数据时,系统要付出很大的代价来维护数据库的完整性,否则会面临数据不一致的危险。比如,某系更换系主任后,必须修改与该系学生有关的每一个元组。
3 : 插入异常:如果一个系刚成立,尚无学生,则无法把这个系及其系主任的信息存入数据库。
所以插入操作异常是指应该插入的数据未被插入。4 : 删除异常:如果某个系的学生全部毕业了,则在删除该系学生信息的同时,这个系及其系主任的信息也丢掉了 。
范式
1NF: 属性不可分
第二范式(2NF):符合1NF,并且非主属性完全依赖于码。(更通俗说有主键ID))
第三范式(3NF):符合2NF,并且,消除传递依赖。(3NF是对字段冗余性的约束,即任何字段不能由其他字段派生出来,它要求字段没有冗余)
部分函数依赖(partial functional dependency)和完全函数依赖(full functional dependency)
部分函数依赖是指如果X→Y,并且存在X的一个真子集X0,使得X0→Y,则称Y对X部分函数依赖
完全函数依赖是指指如果X→Y,并且不存在任何一个X的一个真子集X0,使得X0→Y,则称Y对X完全函数依赖。
如果非主属性B函数依赖于主属性A,而且A的任何一个真子集不能->B,则称B完全函数依赖于A;反之,若A的存在一个真子集能->B,则称B完全函数依赖于A。
例:成绩表(学号,课程号,成绩)关系中,
完全函数依赖:(学号,课程号)→ 成绩,学号 -\→ 成绩,课程号 -\→ 成绩,所以(学号,课程号)→ 成绩 是完全函数依赖
传递函数依赖(Transitive functional dependency)
In Database Management System, a transitive dependency is a functional dependency which holds by virtue of transitivity. A transitive dependency can occur only in a relation that has three or more attributes. Let A, B, and C designate three distinct attributes (or distinct collections of attributes) in the relation. Suppose all three of the following conditions hold:
- A → B
- It is not the case that B → A
- B → C
Then the functional dependency A → C (which follows from 1 and 3 by the [axiom of transitivity]) is a transitive dependency.
In database normalization, one of the important features of third normal form is that it excludes certain types of transitive dependencies. E.F. Codd, the inventor of the relational model, introduced the concepts of transitive dependence and third normal form in 1971.
Example
A transitive dependency occurs in the following relation:
The functional dependency {Book} → {Author Nationality} applies; that is, if we know the book, we know the author's nationality. Furthermore:
- {Book} → {Author}
- {Author} does not → {Book}
- {Author} → {Author Nationality}
Therefore {Book} → {Author Nationality} is a transitive dependency.
Transitive dependency occurred because a non-key attribute (Author) was determining another non-key attribute (Author Nationality).