Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the foreign key constraint level of mysql

Shulou Source: shulou.com Published: 2022-05-31 10:55:00 09月28日 Update

This article mainly introduces mysql what foreign key constraint level related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this mysql what foreign key constraint level article, let's take a look at it.

1. Cascade mode.

When the update/delete record is on the master table, the matching record of the update/delete slave table is synchronized.

2. Set null mode.

When the update/delete record is on the master table, the column that matches the record on the slave table is set to null, but it should be noted that the foreign key column of the child table cannot be notnull.

3. No action mode.

If there are matching records in the child table, update/delete is not allowed to operate on the candidate key corresponding to the parent table.

4. Restrict method, which is the same as no action.

Check the foreign key constraint immediately.

5. Set default mode, white space may be displayed in the visualization tool SQLyog.

When the parent table changes, the child table sets the foreign key column to the default value, but Innodb does not recognize it.

Example

-Department table create table dept (id int primary key,dept_name varchar (50), dept_location varchar (50));-employee form CREATE TABLE emp (eid int primary key,name varchar (50) not null,sex varchar (10), dept_id int) Add a foreign key to the dept_id of the employee table and point to the primary key alter table emp add foreign key (dept_id) references dept (id) of the department table. This is the end of the article on "what foreign key constraint level does mysql have?" Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "what foreign key constraint level mysql has". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Tags: Grades methods knowledge content employees articles departments same value examples tools directions easy to operate articles methods easy to understand more fruits patterns see Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Xiaomi macOS Microsoft MariaDB