Mysql inserts data in batches, mysql inserts data
What should I do if MySQL inserts multiple records using INSERT? The following describes how to INSERT multiple records using INSERT in MySQL for your reference.
If you see this title, you may ask, is there anything you can say about it? Won't you be able to INSERT multiple records after multiple INSERT statements are called! However, using this method increases the load on the server, because every SQL Server executes the same SQL Analysis and Optimization operations. Fortunately, MySQL provides another solution, that is, using an INSERT statement to INSERT multiple records. This is not a standard SQL syntax, so it can only be used in MySQL.
Insert into users (name, age)
VALUES ('Yao Ming ', 25), ('bill Gates', 50), ('marker', 600 );
The preceding INSERT statement inserts three records into the users table consecutively. It is worth noting that the VALUES of each record must be placed in a pair (…) after VALUES in the preceding INSERT statement (...) "," Is used in the middle. Suppose there is a table table1
Create table table1 (n INT );
If you want to insert five records into Table 1, the following statement is incorrect:
Insert into table1 (I) VALUES (1, 2, 3, 4, 5 );
MySQL will throw the following error
ERROR 1136: Column count doesn't match value count at row 1
The correct statement is as follows:
Insert into t able1 (I) VALUES (1), (2), (3), (4), (5 );
Of course, this statement can also omit the column name, so that the number of values in each pair of brackets must be consistent, and this number must be consistent with the number of columns. For example:
Insert into t able1 VALUES (1), (2), (3), (4), (5 );