In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to avoid repeatedly inserting data in the MySQL database. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
01 insert ignore into means that when inserting data, if the data exists, the insertion is ignored. The prerequisite is that the inserted data field has a primary key or unique index. The test SQL statement is as follows. When inserting this data, the MySQL database will first retrieve the existing data (that is, the idx_username index). If it exists, ignore the insertion. If it does not exist, the data will be inserted normally:
02 on duplicate key update: when inserting data, if the data exists, the update operation is performed. The prerequisite is the same as above, and the inserted data field has the primary key or unique index set. The test SQL statement is as follows. When inserting this record, the MySQL database will first retrieve the existing data (idx_username index). If it exists, perform the update update operation. If it does not exist, insert it directly:
03 replace into means that when inserting data, if the data exists, delete and then insert. The prerequisite is the same as above. The inserted data field needs to set a primary key or unique index. The test SQL statement is as follows. When inserting this record, the MySQL database will first retrieve the existing data (idx_username index). If it exists, delete the old data first and then insert it. If it does not exist, insert it directly:
04 insert if not exists means insert into... Select... Where not exist., this method is suitable for inserting a data field without setting a primary key or unique index. When inserting a piece of data, first determine whether the data exists in the MySQL database. If it does not exist, insert normally. If so, ignore:
This is how to avoid repeatedly inserting data in the MySQL database shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to 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.