Hit enter after type your search item

How to insert multiple rows in SQL?

In the INSERT INTO statement tutorial, we have seen how to enter new records into the database tables. You may use column names with VALUES or without using the column names for inserting records.

In many scenarios, you may require entering multiple rows by using the single query of SQL. In this tutorial, I will show you how to enter two or more records by INSERT INTO statement.

First way – Separating VALUES part by a comma

As using simple INSERT INTO statement, we used this statement for entering single record (for our example employee table):


For entering multiple records just separate the VALUES by commas. See the example below:

The above query will enter multiple records into the sto_employees table. You can see, after the VALUES keyword, the first row values are enclosed in parenthesis. This is followed by a comma and then second row values and so on.

This single query should enter records in MS SQL Server as well as MySQL database table.

Insert multiple records without specifying the column names

Multiple records can also be entered without providing the column names (just like in the INSERT INTO command with single record).

In that case, you have to provide all column name values in the same sequence as in the actual physical table. Otherwise, an error may be raised if fewer values are provided than the number of columns in the table or if data type mismatch.

The following query inserts three records in the employee’s table without using the column names:


Again, this query is tested on MS SQL Server as well as MySQL database.

Second Way – Using INSERT INTO & SELECT statements

The combination of INSERT INTO and SELECT statements also allows you entering multiple records by single statement. However, this is used to copy data from one table to another.

The source table (from where you are copying data) is specified in the SELECT statement. The target table (where you are inserting records) is specified in the INSERT INTO command.

The following example shows an example query:


In that case, the complete table rows of sto_employees will be inserted into the employee_sub table. The columns sequence and specification must be the same (names can be different).

You may also use WHERE clause in SELECT statement for inserting specific rows. I have written a detailed guide of using this option in INSERT INTO with SELECT for copying data.

Third way: The UNION Operator

In the third way of inserting multiple rows by single query is using the UNION operator. The UNION operator is basically used to combine the results of SELECT statements.

So, again this technique uses INSERT INTO and SELECT statement, however rather than copying the data from one table to another, you may insert data with independent values (just like the first way).

The INSERT INTO specifies the target table while in the SELECT statements, values are specified. Multiple SELECT statements are combined by the UNION operator as shown in the query below:


The result-set before and after executing this query (for demo only):

SQL Insert multiple rows

Note: This query is tested on MS SQL Server database.

This div height required for enabling the sticky sidebar