Constraints
What is constraint?
constraint is a "provision" that requires data to meet what conditions .
There are several constraints:
PRIMARY KEY constraint: form: primary key ( field name );
meaning (function): The value of the setting field can be used to "uniquely determine a row of data", in fact, the meaning of "primary key".
Unique constraint: form: Unique key ( field name );
meaning (function): Make the value of the Set field "Unique", naturally also distinguishable.
FOREIGN KEY constraint: form: foreign key ( field name ) references Other table names ( corresponding to field names in other tables );
Meaning (function): The value of the Set field must already be in the corresponding field in the corresponding table to which it is determined.
non-null constraint: form: NOT NULL is actually the "notnull" attribute thatwas written when a field was set.
This constraint can only be written on the field property;
Default constraints: form: default XX value; In fact, the default Value property that is written when you set a field
This constraint can only be written on the field property;
CHECK constraints: form: check(some kind of judgment statement), such as:
CREATE TABLE Tab1 (
Age tinyint,
Check (age>=0 and age <100)/* This is the checking constraint * /
)
In fact, primary KEY constraints, unique constraints, foreign key constraints, are just " 2 different angles of the same thing", they are also known as "PRIMARY key index", "Unique index", "Foreign Key Index".
MySQL in constraints