SQL INSERT Multiple Rows

Many times developers ask that is it possible to insert multiple rows into a single table in a single statement. Currently, developers have to write multiple insert statements when they insert values in a table. It is not only boring but also time-consuming.

Let us see few practical examples to understand this concept more clearly. We will use the MySQL database for writing all the queries.

Example 1:

To create a table in the database, first, we need to select the database in which we want to create a table.

Then we will write a query to create a table named student in the selected database 'dbs'.


SQL INSERT Multiple Rows

The student table is created successfully.

Now, we will write a single query to insert multiple records in the student table:


SQL INSERT Multiple Rows

To verify that multiple records are inserted in the student table, we will execute the SELECT query.


IDNamePercentageLocationDateOfBirth
1Manthan Koli79Delhi2003-08-20
2Dev Dixit75Pune1999-06-17
3Aakash Deshmukh87Mumbai1997-09-12
4Aaryan Jaiswal90Chennai2005-10-02
5Rahul Khanna92Ambala1996-03-04
6Pankaj Deshmukh67Kanpur2000-02-02
7Gaurav Kumar84Chandigarh1998-07-06
8Sanket Jain61Shimla1990-09-08
9Sahil Wagh90Kolkata1968-04-03
10Saurabh Singh54Kashmir1989-01-06

The results show that all ten records are inserted successfully using a single query.

Example 2:

To create a table in the database, first, we need to select the database in which we want to create a table.

Then we will write a query to create a table named items_tbl in the selected database 'dbs'.


SQL INSERT Multiple Rows

The table named items_tbl is created successfully.

Now, we will write a single query to insert multiple records in the items_tbl table:


SQL INSERT Multiple Rows

To verify that multiple records are inserted in the items_tbl table, we will execute the SELECT query.


IDItem_NameItem_QuantityItem_PricePurchase_Date
1Soap52002021-07-08
2Toothpaste2802021-07-10
3Pen10502021-07-12
4Bottle12502021-07-13
5Brush3902021-07-15
6Notebooks1010002021-07-26
7Handkerchief31002021-07-28
8Chips Packet5502021-07-30
9Marker2302021-08-13
10Scissors1602021-08-13

The results show that all ten records are inserted successfully using a single query.


Next TopicSQL UPDATE




Latest Courses