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.
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.
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.
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'
The maximum number of rows that can be inserted in a single INSERT statement is 1000.
Just separate the values by comma.
INSERT INTO
tablename (colname1, colname2, colname3)
VALUES
('foo1', 'bar1', 'waa1'),
('foo2', 'bar2', 'waa2'),
('foo3', 'bar3', 'waa3')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With