- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Inserting multiple rows in MySQL?
Insert multiple rows in MySQL with the help of “values”. You can enclose the values with parentheses set with comma separation. The syntax is as follows to insert multiple rows in MySQL.
insert into yourTableName(yourColumnName1,yourColumnName2,..............yourColumnNameN) values(value1,value2,...valueN),(value1,value2,...valueN),(value1,value2,...valueN),...........((value1,value2,...valueN);
Let us now first create a table in MySQL −
mysql> create table InsertMultipleRowsDemo -> ( -> Id int, -> Name varchar(200), -> Age int -> ); Query OK, 0 rows affected (0.45 sec)
Apply the above syntax to insert multiple rows. The query is as follows −
mysql> insert into InsertMultipleRowsDemo(Id,Name,Age) values(1,'John',23),(2,'Carol',24),(3,'Johnson',21),(4,'Smith',20),(5,'David',26); Query OK, 5 rows affected (0.31 sec) Records: 5 Duplicates: 0 Warnings: 0
Display all records with the help of select statement. The query is as follows −
mysql> select *from InsertMultipleRowsDemo;
The following is the output −
+------+---------+------+ | Id | Name | Age | +------+---------+------+ | 1 | John | 23 | | 2 | Carol | 24 | | 3 | Johnson | 21 | | 4 | Smith | 20 | | 5 | David | 26 | +------+---------+------+ 5 rows in set (0.00 sec)
Advertisements