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 does foreign key mean in mysql

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly introduces the meaning of foreign keys in mysql, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

A foreign key is a keyword, and if a public keyword is the primary keyword in one relationship, then the public keyword is called the foreign key of another relationship. The foreign key represents the correlation between the two relationships. Foreign keys can maintain data consistency and integrity, and the main purpose is to control the data stored in the foreign key table.

Introduction to foreign keys:

If the public keyword is the primary keyword in one relationship, then the common keyword is called the foreign key of another relationship. Thus it can be seen that the foreign key represents the correlation between the two relationships. A table with the foreign key of another relationship as the primary key is called the master table, and the table with this foreign key is called the slave table of the master table. Foreign keys are also called foreign keywords.

Function:

The main purpose of maintaining data consistency and integrity is to control the data stored in the foreign key table. To associate the two tables, the foreign key can only refer to the values of the columns in the table or use null values.

Prevent execution

Insert a new row from a table whose foreign key value is not the primary key value of the primary table.

If the foreign key value is modified from the table, the modification is prevented if the new value is not the primary key value of the primary table.

Delete rows from the master table, whose primary key value exists in the slave table to prevent deletion (to delete, you must first delete the relevant rows from the slave table)

The master table modifies the primary key value, and the old value exists in the slave table to prevent the modification (if you want to modify, you must first delete the relevant rows of the slave table).

Cascade execution

Delete rows from the main table, along with related rows from the table

The primary table modifies the primary key value, along with the foreign key value of the related rows of the slave table. Two methods are provided for users to choose from. No matter which method you choose, there will be no extra rows from the table. From another point of view, it is consistent with the flag in the master table by rejecting the flag of the same thing in the slave table is inconsistent with the master table.

Thank you for reading this article carefully. I hope the article "what is the meaning of foreign keys in mysql" shared by the editor will be helpful to everyone? at the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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

Internet Technology

Wechat

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

12
Report