Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting more than one record with a single insert statement

Tags:

sql

mysql

How can MySQL insert multiple records by executing a single insert statement?

The problem at hand involves 1 to 10 records, depending upon user input.

like image 886
nectar Avatar asked Jun 01 '10 18:06

nectar


People also ask

Is it possible to insert multiple rows simultaneously?

Tip: Select the same number of rows as you want to insert. For example, to insert five blank rows, select five rows. It's okay if the rows contain data, because it will insert the rows above these rows. Hold down CONTROL, click the selected rows, and then on the pop-up menu, click Insert.

Can you do multiple inserts in SQL?

If you want to insert more rows than that, you should consider using multiple INSERT statements, BULK INSERT or a derived table. Note that this INSERT multiple rows syntax is only supported in SQL Server 2008 or later. To insert multiple rows returned from a SELECT statement, you use the INSERT INTO SELECT statement.

Can you insert more than one row at a time using an insert statement with a value clause?

You use the VALUES clause in the INSERT statement to insert a single row or multiple rows into a table. An example of this is to insert a new row into the DEPARTMENT table. The columns for the new row are as follows: Department number (DEPTNO) is 'E31'

How many rows can you insert a table with one statement?

The maximum number of rows that can be inserted in a single INSERT statement is 1000.


1 Answers

Just separate the values by comma.

INSERT INTO
    tablename (colname1, colname2, colname3)
VALUES 
    ('foo1', 'bar1', 'waa1'), 
    ('foo2', 'bar2', 'waa2'), 
    ('foo3', 'bar3', 'waa3')
like image 138
BalusC Avatar answered Sep 20 '22 01:09

BalusC