Get the App
SLTechnology News&Howtos  ›  Database  › 

Example of mysql entering multiple lines at a time

Shulou Source: shulou.com Published: 2022-06-01 01:54:44 10月03日 Update

This article mainly introduces mysql input multi-line example, with a certain reference value, friends can refer to the need. I hope you all have a lot to gain after reading this article. Let's take a look at it together.

mysql can insert multiple records at once through the insert statement, but this statement is a transaction, so it must succeed and fail. Each record in the statement is enclosed by ().

And the syntax is mysql itself, not standard syntax, can not be universal.

mysql inserts multiple pieces of data at once:

INSERT INTO hk_test(username, passwd) VALUES('qmf2', 'qmf2'),('qmf3', 'qmf3'),('qmf4', 'qmf4'),('qmf5', 'qmf5');

First, let's 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 once, sql insert 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 SQL statements inserted one by one, except that multiple insert statements use commas to separate each data.

The results were as follows:

AuthID

AuthFN

AuthMN

AuthLN

1006

H

S.T1007

J

CO1008

B

E1009

RMR1010

JKT1011

JG.N1012

A

p1013

A

W1014

N

A thank you for reading this article carefully, hope Xiaobian share mysql input multi-line example content to help everyone, but also hope that everyone more support, pay attention to the industry information channel, encounter problems to find, detailed solutions waiting for you to learn!

Tags: Statements multiple data articles examples multiple lines input success one-time syntax transaction code value content but can be passed at the same time methods friends standards Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Docker Xiaomi vpn MySQL