Home >Database >Mysql Tutorial >Can mysql input multiple rows of records at one time?

Can mysql input multiple rows of records at one time?

(*-*)浩
(*-*)浩Original
2019-05-09 10:49:315376browse

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]));].

Can mysql input multiple rows of records at one time?

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:

##AuthID AuthFN AuthMN AuthLN 1006 H S.T1007 JCO1008 B##1009 MRJJ##1012 A1013ANA










##E
R
##1010

K
T 1011

G.
N

p

W
##1014


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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn