MYSQL_Constraints

Constraint Constraints:

imposes certain conditions on the data of the fields in the inserted table.

constrained into five kinds:
primary key constraint:primary key    The field value of the field that is required as the primary key is not null and unique
Non-empty constraint: not null    Requirement: Fields with non-null constraints cannot be null values.
Unique constraint:unique    Fields that require unique constraints cannot be repeated, but can be null.
Checkability constraints: check(conditions) - check(gender in(‘f’,’m’))    It is required to meet the check condition of the field when inserting data, but it can be nullPS: the chuck is invalid in mysql, generally use the enumeration gender enum('f', 'm') instead of the gender varchar (1 Check(gender in('f','m'))
foreign key constraint: foreign key    Requirement: Field A with foreign key constraints must depend on another field B,         Field B must have a primary key constraint.   The value of field A is either null or must be the value in field B.

例:

empno int *primary key*,
ename varchar(20) *not null*,
idcard varchar(18) *unique*,
gender *enum('f','m')*,
mgr int *foreign key(mgr) references t_05(empno)*

序:

The field that is the primary key, usually not the main information in the table, can be used as the serial number of the information record. The sequence number is preferably an ordered sequence. The

auto_increment keyword is used to auto-increment fields that have primary key constraints.

使用:   Create table tname(   Tid int primary key auto_increment,   ......   );

last_insert_id()function:   Role: Get the value of the last insertion of the sequence.   Usage: select last_insert_id();