Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Insert multiple rows in a single MySQL query
Let us first create a table −
mysql> create table DemoTable1384 -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAge int -> ); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command. Here, we are inserting multiple rows in a single query −
mysql> insert into DemoTable1384(StudentName,StudentAge) values('Chris Brown',21),('David Miller',22),
-> ('Carol Taylor',19),('Adam Smith',23);
Query OK, 4 rows affected (0.11 sec)
Records: 4 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable1384;
This will produce the following output −
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 21 | | 2 | David Miller | 22 | | 3 | Carol Taylor | 19 | | 4 | Adam Smith | 23 | +-----------+--------------+------------+ 4 rows in set (0.00 sec)
Advertisements
