In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article is to share with you about how to set foreign keys in MySQL, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
The role of foreign keys:
The main purpose of maintaining data consistency and integrity is to control the data stored in the foreign key table. Associate the two tables, and the foreign key can only refer to the values of the columns in the table!
For example:
A b two tables
Customer number and customer name are stored in table a
The order of each customer is stored in table b
After having a foreign key
You can delete customer x from table an only after you are sure that there is no order for customer x in table b
The premise of establishing a foreign key: the column of this table must be of the same type as the foreign key (the foreign key must be the outer primary key).
Specify primary key keyword: foreign key (column name)
Reference foreign key keyword: references (foreign key column name)
Event trigger limits: on delete and on update, you can set parameters cascade (follow foreign key changes), restrict (limit foreign key changes in the table), set Null (set null), set Default (set default), [default] no action
For example:
OutTable table primary key id type int
Create a table that contains foreign keys:
Create table temp (
Id int
Name char (20)
Foreign key (id) references outTable (id) on delete cascade on update cascade)
Description: set the id column as the foreign key reference id column of the external outTable as the value of the foreign key delete the corresponding column in this table when the value of the foreign key changes the corresponding column value in this table.
The above is how to set foreign keys in MySQL. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.