Three database paradigms and five constraints

database

 今天小编来讲一下数据库的相关知识点,数据库的三大特性可谓是:实体属性和关系。

 实体:表; 属性:表中的数据(字段); 关系:表与表之间的关系;

 数据库设计三大范式(重点):

First Normal Form (1NF): Each column (each field) in the data table must be the smallest unit that cannot be split, that is, to ensure the atomicity of each column;

                            例如:userInfo:山东省烟台市  131777368781           userAds:山东0省烟台市  userTel:131777368781

Second Normal Form (2NF): After satisfying 1NF, all columns in the table are required to depend on the primary key, and no column can be unrelated to the primary key, that is to say, a table only describes one thing;

                            例如:订单表只描述订单相关的信息,所以所有字段都必须与订单id相关       产品表只描述产品相关的信息,所以所有字段都必须与产品id相 关;因此不能在一张表中同时出现订单信息与产品信息;如下图所示:

Third normal form (3NF): The second normal form (2NF) must be satisfied first, requiring: each column in the table is only directly related to the primary key instead of indirectly related, (each column in the table can only depend on the primary key);

                             例如:订单表中需要有客户相关信息,在分离出客户表之后,订单表中只需要有一个用户id即可,而不能有其他的客户信息。因为其他的客户信息直接关联于用户id,而不是直接与订单id直接相关。

[How to better distinguish the three paradigms]

     第 一范式和第二范式在于有没有分出两张表,第二范式是说一张表中包含了所种不同的实体属性,那么要必须分成多张表, 第三范式是要求已经分成了多张表,那么一张表中只能有另一张表中的id(主键),而不能有其他的任何信息(其他的信息一律用主键在另一表查询)。

[Five database constraints]

1.primary KEY: set the primary key constraint; 2.UNIQUE: set the unique constraint, no duplicate values; 3.DEFAULT default value constraint, height DOUBLE(3,2)DEFAULT 1.2 If the height is not entered, the default value is 1,2 4. NOT NULL: set a non-null constraint, the field cannot be empty; 5.FOREIGN key: set a foreign key constraint.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325520931&siteId=291194637