MySQL BULK INSERT data

Source: Internet
Author: User
Tags bulk insert

MySQL inserts multiple records using INSERT, what should I do? Here is a detailed description of how MySQL inserts multiple records using insert for your reference.

See this title maybe everyone will ask, this has what to say, call multiple INSERT statements can not insert more than one record! But use this method to increase the load on the server, because every SQL Server executes the same SQL analysis, optimization, and so on. Fortunately, MySQL provides another solution, which is to use an INSERT statement to insert multiple records. This is not a standard SQL syntax, so it can only be used in MySQL.

INSERT into users (name, age)

VALUES (' Yao ', 25), (' Bill Gates ', 50), (' Martians ', 600);

The INSERT statement above inserts 3 records into the users table consecutively. It is important to note that the values in the INSERT statement above must be placed in pairs (...) for each record. In the middle, use "," split. Suppose there is a table table1

CREATE TABLE table1 (n INT);

If you want to insert 5 records into Table1, the following is the wrong way to write:

INSERT into table1 (i) VALUES (1,2,3,4,5);

MySQL will throw the following error

ERROR 1136:column Count doesn ' t match value count at row 1

The correct wording should be:

INSERT into T Able1 (i) VALUES (1), (2), (3), (4), (5);

Of course, this notation can also omit column names, so that the number of values in each pair of parentheses must be the same, and that number must be the same as the number of columns. Such as:

INSERT into T able1 VALUES (1), (2), (3), (4), (5);

MySQL BULK INSERT data

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.