Can I insert two or more rows in a MySQL table at once?


Yes, we can insert two or more rows in a table at once. Following is the syntax −

insert into yourTableName(yourColumnName1,yourColumnName2) values(yourValue1,yourValue2),(yourValue1,yourValue2),.........N;

Let us first create a table −

mysql> create table DemoTable811(
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentName varchar(100),
   StudentAge int
);
Query OK, 0 rows affected (0.54 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable811(StudentName,StudentAge) values('Chris',21),('Robert',22),('David',20),('Bob',19),('Carol',23);
Query OK, 5 rows affected (0.14 sec)
Records: 5 Duplicates: 0 Warnings: 0

Display all records from the table using select statement −

mysql> select *from DemoTable811;

This will produce the following output −

+-----------+-------------+------------+
| StudentId | StudentName | StudentAge |
+-----------+-------------+------------+
|         1 | Chris       |         21 |
|         2 | Robert      |         22 |
|         3 | David       |         20 |
|         4 | Bob         |         19 |
|         5 | Carol       |         23 |
+-----------+-------------+------------+
5 rows in set (0.00 sec)

Updated on: 03-Sep-2019

79 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements