Foreign key constraints and modeling

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

Foreign key constraints and modeling

For the relationship of mysql, we can use modeling software to describe the database table in detail. Both PowerDesigner and sqlyog can be used to build the relationship model.

The advantage of PowerDesigner is that it can make Chinese comments on tables, and sqlyog cannot have Chinese comments.

The schematic diagram of PowerDesigner modeling is as follows:

image

sqlyog modeling requires clicking on the new schema designer:

image

The schematic diagram of the modeling is as follows:

image

Foreign key constraints can double-click the relationship line to add foreign key constraints. There are four different options for foreign key constraints: CASCADE, SET NULL, NO ACTION, RESTRICT.

1.CASCADE: Delete or update the corresponding row from the parent table, and automatically delete or update the matching row from the table. [ON DELETE CANSCADE and ON UPDATE CANSCADE are both supported by InnoDB. ]

2.SET NULL: Delete or update the corresponding row from the parent table, and set the foreign key column in the child table to be empty. [Note that these only work if the foreign key column is not set to NOT NULL. Both ON DELETE SET NULL and ON UPDATE SET SET NULL are supported by InnoDB. ]

3.NO  ACTION: InnoDB refuses to delete or update the parent table.

4. RESTRICT: Refuse to delete or update the parent table. [Specifying RESTRICT (or NO ACTION) has the same effect as ignoring the ON DELETE or ON UPDATE options. ]

The operation diagram is as follows:

image

Four options can be set in the drop-down list.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326483600&siteId=291194637