Summer self-study day 09 | database (I) – SQL, DDL
Summer self-study day 10 | database (II) – DML
Summer self-study day 10 | database (III) – DQL
Summer self-study day 11 | database (IV) – constraints
Summer self-study day 12 | database (V) – multi table, database design
Summer self-study day 13 | database (VI) – multi table query
Summer self-study day 14 | database (VII) – affairs
- Limit the data of the table to ensure the correctness, effectiveness and integrity of the data.
- Category: add after data name
- Primary key, non empty and unique, is the unique identification of the data
ALTER table t_name DROP PRIMARY KEY;
- Note that primary key deletion is different from non empty deletion. Modify is used for non empty deletion.
- Self growth
AUTO INCREMENT: the value of automatic growth is only related to the previous record
- Not null, value cannot be empty
- Unique, the value cannot be repeated
ALTER table t_name DROP INDEX id;
- In a master-slave table relationship, if the slave table data is deleted, the data of a column in the master table will also be affected due to the association relationship. By adding foreign key constraints, data cannot be easily deleted from the table.Let the relationship between tables exist to ensure the correctness of data.
Foreign key column, constraint foreign key name foreign key reference main table name;
- An example:
--One party main table, department table
- When changing the foreign key ID, cascade can be used to update the foreign key values associated with the master-slave table.
- Add cascade: on update cascade
ALTER TABLE employ ADD CONSTRAINT emp_dep_fk FOREIGN KEY (dep_id) REFERENCE department(id) ON UPDATE CASCADE;
- Delete cascade: on delete cascade
This work adoptsCC agreement, reprint must indicate the author and the link to this article