In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to insert multiple records in an insert statement about mysql. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Insert statements are commonly written:
INSERT INTO items (name,city,price,number,picture) VALUES ('Nike sneakers', 'Guangzhou', 500jpg')
In this way, you can only insert one piece of data at a time, and if you want to insert more than one piece of data, you have to call this sql statement multiple times, which means establishing a connection to the database multiple times. However, this will increase the load on the server, because every time the SQL server is executed, the SQL will be analyzed, optimized, and so on. Fortunately, MySQL provides another solution, which is to use an INSERT statement to insert multiple records. This is not a standard SQL syntax, so it can only be used in MySQL.
An INSERT statement is inserted into a batch of data:
INSERT INTO [Table name] ([column name], [column name]) VALUES ([column value], [column value]), ([column value], [column value]), ([column value], [column value])
As you can see, the difference from the original regular INSERT statement is only the arrangement of added values after the VALUES, and each record is separated by a comma in the English input method state, is it so easy.
Example:
INSERT INTO items (name,city,price,number,picture) VALUES ('Nike sneakers', 'Guangzhou', 500jpg'), ('Nike sneakers', 'Guangzhou') ('Nike sneakers', 'Guangzhou', 'Guangzhou', 'Nike sneakers', 'Guangzhou')
In this way, two pieces of data are inserted at one time.
Recommendations:
In a program, when inserting bulk data, it is best to use this method of one-time insertion through an INSERT statement. This prevents the program from establishing multiple connections to the database, thus increasing the load on the server.
This is the end of the article on "how to insert multiple records in one insert sentence of mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.