Home > Database > Mysql Tutorial > body text

How to add multiple rows of data in mysql?

藏色散人
Release: 2019-05-08 10:35:09
Original
13114 people have browsed it

How to add multiple rows of data in mysql?

Mysql can insert multiple records at one time through the insert statement, but this statement is a transaction, so it will succeed if it succeeds, and it will fail if it fails. Each record in the statement is enclosed by (). And this syntax is mysql's own, not standard syntax, and cannot be used universally.

mysql inserts multiple pieces of data at one time:

INSERT INTO hk_test(username, passwd) VALUES
 
('qmf2', 'qmf2'),('qmf3', 'qmf3'),('qmf4', 'qmf4'),('qmf5', 'qmf5')
 
GO
Copy after login

Let’s first create a table Authors:

CREATE TABLE Authors(
AuthID SMALLINT NOT NULL PRIMARY KEY,
AuthFN VARCHAR(20),
AuthMN VARCHAR(20),
AuthLN VARCHAR(20)
)
ENGINE=INNODB;
Copy after login

Then insert multiple pieces of data into the table at one time, sql insert code 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');
Copy after login

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:

How to add multiple rows of data in mysql?

The above is the detailed content of How to add multiple rows of data in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!