1. PRIMARY KEY constraint (PRIMARY key):
The primary key is a special field of the table. This field uniquely identifies each piece of information in the table. The relationship between a primary key and a record is like a relationship between a person and a man. The primary key is used to identify each record, and the primary key value for each record is different. is used to indicate a person's identity, everyone has a unique * * * number. Set a table's primary key to set a table's field as a primary key when creating a table
The primary purpose of the primary key is to help MySQL find a piece of information in the table at the fastest speed. The primary key must meet the condition that primary key value must be unique , the value of the primary key field for any two records in the table cannot be the same; < Span style= "font-family: ' Microsoft Jas Black ', ' Microsoft Yahei '; font-size:20px;" The value of the primary key is a non-null value of . The primary key can be single field , can also be A combination of multiple fields .
Simply put: if a field is defined as a primary key, the field value must be unique and cannot be empty. Each table can define only one primary key, but you can define multiple fields to be combined into one primary key type .
2. Unique key constraint (unique):
Uniqueness means that the value of the field in all records cannot recur. Setting a table's uniqueness constraint is when you create a table, some special fields of the enclosing tag are added with a unique constraint. A uniqueness constraint will guarantee that the value is unique in the unique field.
In simple terms: If a field is defined as a unique key, the field value must be unique and can be null. Each table can define multiple unique keys.
3, FOREIGN KEY constraints (CONSTRAINT, FOREIGN Key, REFERENCES):
A foreign key is a special field of a table. The main is to establish the association between tables. The foreign key must depend on the primary key of the parent table that the database already exists.
Simply put: if a field is defined as a foreign key, the field needs to rely on the primary key of another table, which is associated with another table. The other table is the parent table of this table, and the foreign key can be null. And the child table foreign key data type must be the same as the parent table data type.
4. Non-null constraint (NOT NULL):
Ensure that the value inserted by this field cannot be empty.
5. Automatic increment of table attributes (Auto_increment):
Field values are automatically incremented, no duplicate values occur, and are generally not empty.
mysql-Constraint type