※? Primary key constraint: primary key
※? Unique key: uniqueness constraint
※? Foreign key constraints: foreign keys
※? Non-empty constraint: non-empty
※? Default constraint: default value
Second, the primary key constraint:
A table can only have one primary key. If you forget to set the primary key constraint when building a table, the query speed of columns set as primary keys will be very fast, so clustered indexes are generally used, which we will talk about later.
Add primary key constraint: set your age table as the primary key.
Grammar: alter? Add primary key to table name; (column name)? ※? You can have multiple column names.
Third, foreign key constraints:
What is a foreign key? When you need to use the primary key of another table as the primary key of this table when building a table, you need to set a foreign key. If you want to delete the data in the table after setting the outer room, it will be deleted in cascade or by default.
Add foreign key constraint: set the cno of this table as a foreign key.
Syntax: alter table table name add foreign key references? Name (column name) of the associated table;
Fourth, non-empty constraints:
When inserting new data, the corresponding column cannot be empty. Non-empty constraints are relative to the default constraints.
Add a non-empty constraint:
Syntax: alter table table name modify column name column type not null; ?
Verb (abbreviation for verb) default value constraint: default value:
If no value is inserted when inserting, the default value will be automatically inserted. Default value constraints are relative to non-empty constraints.
Add default constraint:
Syntax: alter table table name add column name column type not null default value' default value';
6. Uniqueness constraint:
The content in this column can only be unique and cannot be repeated.
Add a unique constraint:
? Syntax: alter table column name add unique? You can have multiple column names separated by commas. ※.