第一范式
INF
数据表中所有字段都是不可分割的原子值
create table student2(
id int primary key,
name VARCHAR(20),
address VARCHAR(30)
)
insert into student2 VALUES(1,"li","四川省成都市武侯大道100号")
字段值还可以继续拆分,就不满足第一范式
create table student4(
id int primary key,
name VARCHAR(20),
cuntry VARCHAR(30),
privence VARCHAR(30),
city VARCHAR(30),
details VARCHAR(30)
)
insert into student4 VALUES(1,"li","中国","四川省","成都市","武侯大道100号")
范式设计越详细 ,对于某些基本操作可能更好,但是不一定都是好处
第二范式
必须满足第一范式的前提下,第二范式要求 ,除主键外的每一列都必须完全依赖与主键
如果要出现不完全依赖,只可能发生在联合主键的情况下
创建一个订单表 :
create table myorder(
product_id int,
customer_id int,
product_name VARCHAR(20),
customer_name VARCHAR(20),
primary key(product_id,customer_id)
问题 ,
除主键以外的其他列 ,只依赖于主键的部分字段,
拆表:
create table myorder1(
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)
)
第三范式
3nf
必须先满足第二范式,除开主键列的其他列之间不能有传递依赖关系
create table myorder5(
order_id int primary key,
product_id int,
customer_id int
)
create table customer5(
id int primary key,
name VARCHAR(20),
phone VARCHAR(15)
)