The method of adding multiple rows of data to mysql
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.