Simple Method for inserting multiple rows of records in mysql SQL statements

Source: Internet
Author: User

Insert into is used to insert records in mysql. However, to insert multiple records, insert into or other methods are used to traverse and execute insert into. Let's take a look.

Normally, we use SQL to execute

Insert into 'tabale '('name') VALUE ('name ')

If you want to use php to execute such an SQL statement, you need to execute the following SQL statement to insert multiple rows of records.

Insert into 'tabale '('name') VALUE ('name'), ('name ')

You want to insert more than one entry at a time.


If you want to insert five records into Table 1, the following statement is incorrect:

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 statement is as follows:

Insert into t able1 (I) VALUES (1), (2), (3), (4), (5 );

Of course, this statement can also omit the column name, so that the number of values in each pair of brackets must be consistent, and this number must be consistent with the number of columns. For example:

Insert into t able1 VALUES (1), (2), (3), (4), (5 );

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.