SQL INSERT Multiple RowsMany 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'. The student table is created successfully. Now, we will write a single query to insert multiple records in the student table: To verify that multiple records are inserted in the student table, we will execute the SELECT query.
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'. The table named items_tbl is created successfully. Now, we will write a single query to insert multiple records in the items_tbl table: To verify that multiple records are inserted in the items_tbl table, we will execute the SELECT query.
The results show that all ten records are inserted successfully using a single query. Next TopicSQL UPDATE |