MySQL inserts multiple records using INSERT, what should I do? Here is a detailed description of how MySQL inserts multiple records using insert for your reference.
See this title maybe everyone will ask, this has what to say, call multiple INSERT statements can not insert more than one record! But use this method to increase the load on the server, because every SQL Server executes the same SQL analysis, optimization, 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.
INSERT into users (name, age)
VALUES (' Yao ', 25), (' Bill Gates ', 50), (' Martians ', 600);
The INSERT statement above inserts 3 records into the users table consecutively. It is important to note that the values in the INSERT statement above must be placed in pairs (...) for each record. In the middle, use "," split. Suppose there is a table table1
CREATE TABLE table1 (n INT);
If you want to insert 5 records into Table1, the following is the wrong way to write:
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 wording should be:
INSERT into T Able1 (i) VALUES (1), (2), (3), (4), (5);
Of course, this notation can also omit column names, so that the number of values in each pair of parentheses must be the same, and that number must be the same as the number of columns. Such as:
INSERT into T able1 VALUES (1), (2), (3), (4), (5);
MySQL BULK INSERT data