Table Design Learning 1: Primary key bitsCN.com
1. the data in the table should be atomic, that is, the information contained in the column can satisfy the most efficient query operations, but this is still not enough to reach the first paradigm.
2. each data row must have a unique identifier, namely, the so-called Primary Key)
3. the primary key is a column in the table, which makes each record unique.
4. duplicate data columns cannot be used as primary keys, and ID IDs are not supported. Once a database is intruded, customer data is exposed.
5. the primary key cannot be NULL. if the primary key is NULL, it cannot be unique because other records may contain NULL.
6. when inserting a new record, you must specify the primary key value. if there is no primary key value, it means there is a risk that the primary key value is NULL, and duplicate records may exist in the table. this violates the standard principle.
7. the primary key must be clean and concise, and there should be no redundant content
8. the primary key value cannot be modified. if the primary key value can be changed, the uniqueness of the primary key may be damaged by accidental input of used values.
9. the best way to create a primary key is to create a column that contains the unique primary key, such as the ID column.
Example:
Mysql> create table student (-> id int primary key not null,-> first_name VARCHAR (20),-> last_name VARCHAR (30)->); Query OK, 0 rows affected( 0.16 sec)
Set the id column as the primary key and set the not null constraint so that it is NOT empty.
Create two atomic data columns respectively.
BitsCN.com