In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
It is believed that many inexperienced people don't know what to do about how to delete the foreign key constraints of all tables in the MySQL database. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Overview
Although the foreign key of the database can ensure the consistency and integrity of the data, it also affects the performance of data update to a certain extent. In development, when we use PowerDesigner to build a physical data model, in order to make the structure clear and increase readability, we will create the relationship between the table and the table.
In the actual development, there are generally no foreign keys in the database, Ali's development manual also forces the use of foreign keys and cascading operations, all the concepts of foreign keys must be solved in the application layer. What if a foreign key already exists in the database and needs to be disabled or deleted?
1. Modify the MySQL variable FOREIGN_KEY_CHECKS (batch disable enable foreign keys for all tables)
-- session level disable foreign key constraint SET FOREIGN_KEY_CHECKS = 0;-- session level enable foreign key constraint SET FOREIGN_KEY_CHECKS = 1;-- globally disable foreign key constraint SET GLOBAL FOREIGN_KEY_CHECKS = 0; or SET @ @ GLOBAL.FOREIGN_KEY_CHECKS = 0;-- globally enable foreign key constraint SET GLOBAL FOREIGN_KEY_CHECKS = 1
After the modification is completed, you can view the modified results.
SELECT @ @ FOREIGN_KEY_CHECKS
two。 Bulk delete foreign keys for all tables
Query all foreign key names in schema, then concatenate to generate delete statements, and then execute.
SELECT CONCAT ('ALTER TABLE', TABLE_SCHEMA,'., TABLE_NAME, 'DROP FOREIGN KEY', CONSTRAINT_NAME,';') FROM information_schema.TABLE_CONSTRAINTS c WHERE c.TABLE_SCHEMA = 'database name' AND c.CONSTRAINT_TYPE = 'FOREIGN KEY'
After reading the above, have you mastered how to delete the foreign key constraints of all tables in the MySQL database? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.