1NF
只要字段还能继续拆分,就不能满足第一范式
2NF
在满足第一范式条件下,其他列必须完全依赖于主键列,如果不完全依赖,只可能是联合主键的情况:
订单表
create table myoder(
product_id int,
customer_id int,
product_name varchar(20),
customer_name varchar(20),
primary key(product_id,customer_id)
);
在这张订单表中,product_name 只依赖于 product_id ,customer_name 只依赖于 customer_id 。也就是说,product_name 和 customer_id 是没用关系的,customer_name 和 product_id 也是没有关系的。
这就不满足第二范式
可用拆分方法使其满足第二范式
create table myoder(
order_id int primary key,
product_id int,
customer_id int
);
create table product(
id int primary key,
name varchar(20)
);
create table customer(
id int primary key,
name varchar(20)
);
拆分之后我们可以发现myorder 表中的 product_id 和 customer_id 完全依赖于 order_id 主键,而 product 和 customer 表中的其他字段又完全依赖于主键。满足了第二范式的设计!
3NF
满足第二范式,除主键列之外,其他列之间不能有传递依赖关系
create table myoder(
order_id int primary key,
product_id int,
customer_id int,
customer_phone varchar(20)
);
表中的 customer_phone 有可能依赖于 order_id 、 customer_id 两列,也就不满足了第三范式的设计:其他列之间不能有传递依赖关系。
可以做以下修改,使各列之间不存在依赖传递关系
create table myoder(
order_id int primary key,
product_id int,
customer_id int
);
create table customer(
id int primary key,
name varchar(20),
phone varchar(20)
);
3259

被折叠的 条评论
为什么被折叠?



