Home >Database >Mysql Tutorial >Can mysql input multiple rows of records at one time?
mysql can input multiple rows of records at one time, the syntax is [INSERT INTO [table name]([column name],[column name]) VALUES([column value],[column value])),([ Column value],[Column value])),([Column value],[Column value]));].
This article explains how mysql inserts multiple pieces of data into a table at one time.
Recommended courses: MySQL tutorial
mysql can insert multiple records at one time through the insert
statement, but this statement is a transaction, so it must If you succeed, you succeed; if you fail, you fail. Each record in the statement is enclosed by ()
.
And this syntax is mysql's own, not standard syntax, and cannot be universal.
mysql inserts multiple pieces of data at one time:
INSERT INTO hk_test(username, passwd) VALUES ('qmf2', 'qmf2'),('qmf3', 'qmf3'),('qmf4', 'qmf4'),('qmf5', 'qmf5');
First we create a table Authors:
CREATE TABLE Authors( AuthID SMALLINT NOT NULL PRIMARY KEY, AuthFN VARCHAR(20), AuthMN VARCHAR(20), AuthLN VARCHAR(20) ) ENGINE=INNODB;
Then insert multiple pieces of data into the table at one time , the sql insertion code is as follows:
INSERT INTO Authors VALUES (1006, 'H', 'S.', 'T'), (1007, 'J', 'C', 'O'), (1008, 'B', NULL, 'E'), (1009, 'R', 'M', 'R'), (1010, 'J', 'K', 'T'), (1011, 'J', 'G.', 'N'), (1012, 'A', NULL, 'P'), (1013, 'A', NULL, 'W'), (1014, 'N', NULL, 'A');
In fact, it is very similar to the SQL statements inserted one by one, except that multiple insert statements use commas to separate each piece of data.
The results are as follows:
T | |||
O | |||
##E |
##1009 | ||
R | MR | ##1010 | |
K |
T | 1011 | |
G. |
N | ##1012 | |
p | |||
|
W |
##1014 |
N |
The above is the detailed content of Can mysql input multiple rows of records at one time?. For more information, please follow other related articles on the PHP Chinese website!