A first paradigm 1NF
Data in the table all fields are indivisible atomic value .
create table student(
id int primary key,
name varchar(20),
contact varchar(30)
);
---contact字段是可以拆分的
insert into student values(1,'张三','8159758,17625364718');
insert into student values(2,'李四','6547621,18743627162');
insert into student values(3,'王五','1253512,13345671243');
Contact fields can be divided into landline and mobile phones, it does not meet the first paradigm. The first paradigm does not meet the requirements, it is not a relational database .
However, just to meet the first paradigm, there will be data redundancy is too large, abnormal insertion, deletion abnormalities, modify abnormal problem. For example the following table:
Second, the second normal form 2NF
The first premise paradigm must satisfy, requirements of the second paradigm, each column in addition to the primary key must be entirely dependent on the primary key . If you do not want to appear totally dependent, it can only occur in the case of joint primary key.
---订单表
create table myorder(
product_id int,
customer_id int,
product_name varchar(20),
customer_name varchar(20),
primary key(product_id,customer_id)
);
Question: Name the only product-related and product id, customer name and customer names only related to only rely on the part of the field primary key , it does not meet the second paradigm.
To split the table so that it matches the second paradigm.
---拆表后均完全依赖主键
create table myorder(
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)
);
Third, the Third Normal Form 3NF
Must satisfy the second paradigm, among other primary key column can not have dependencies transfer , i.e. independent of each other.
create table myorder(
order_id int primary key,
product_id int,
customer_id int,
product_name varchar(20)
);
product_name
And also product_id
we have dependencies, so does not meet the third paradigm.