Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the foreign key constraint levels of mysql

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Today, I will talk to you about the foreign key constraint levels of mysql, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

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. After reading the above, do you have any further understanding of the foreign key constraint level of mysql? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report