Normal Forms

<aside> <img src="/icons/dependency_lightgray.svg" alt="/icons/dependency_lightgray.svg" width="40px" /> Functional Dependency

Attribute Y is functionally dependent on attribute X if and only if the value of X uniquely determines the value of Y. Y被X决定,X变Y必变

X determines Y, X → Y

X is called the determinant, Y is called dependent attribute

</aside>

First Normal Form (1NF 第一范式)

Each domain of a column must contain only atomic values, and each column in a record must have at most one value from its domain.

每一列都是不可再分的数据单元 (最小的原子单元)每个字段(列)的值都是单一值

<aside> <img src="/icons/dependency_lightgray.svg" alt="/icons/dependency_lightgray.svg" width="40px" /> Partial Dependency 部分依赖 If the proper subset of candidate key determines non-prime attribute, it is called partial dependency. 某个属性只依赖主键的一部分 eg. 下表中主键为 EmpID 和ProjCode

(EmpID, EmpLName, EmpFName, Dept, ProjCode, Hours)

此时 给出FD:

EmpID → EmpLName, EmpFName, Dep

EmpID, ProjCode → Hours

可以看到EmpID是主键EmpID 和ProjCode的一个子集 此时它就是partial dependency

</aside>

<aside> <img src="/icons/arrow-down-line_pink.svg" alt="/icons/arrow-down-line_pink.svg" width="40px" /> 去除部分依赖 变成第二范式 上文中的表 把partial dependency 的 EmpID → EmpLName, EmpFName, Dep 从1NF中单独提取出来 成为一个单独的表 (EmpID, EmpLName, EmpFName, Dep) 剩下的attribute留下成为一个表 (EmpID, ProjCode, Hours) *此处EmpID下边还应该有虚线表示是 foreign key

</aside>

Second Normal Form (2NF 第二范式)

No Partial Dependency

1NF + every attribute in the table is determined by the entire primary key (but not by any subset)

1NF 基础上 消除非主属性对主属性的部分函数依赖