Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of adding multiple rows of data to mysql

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How to add multiple rows of data to mysql? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

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

Mysql inserts multiple pieces of data at a time:

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

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

Then insert multiple pieces of data into the table at one time. The sql insertion code is as follows:

INSERT INTO Authors VALUES (1006, 'Houses,' S.waters,'T'), (1007, 'Jacks,' NULL,'O'), (1008, 'baked, NULL,' E'), (1009, 'Rises,' Mills,'R'), (1010, 'Jacks,' Knights,'T'), (1011, 'Jacks,' G.') 'N'), (1012,' A', NULL,'P'), (1013,'A', NULL,'W'), (1014,'N', NULL,'A')

It's actually very similar to an inserted SQL statement, except that multiple insert statements use commas to separate each piece of data.

The results are as follows:

Thank you for reading! After reading the above, do you have a general idea of how to add multiple rows of data to mysql? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report