
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to avoid inserting duplicate rows in MySQL?
- Display multiple selected rows using MySQL IN()
- Count(*) rows from multiple tables in MySQL?
- Inserting multiple parameter values into a single column with MySQL?
- MySQL query to count rows in multiple tables
- Insert multiple rows in a single MySQL query
- MySQL query to select multiple rows effectively?
- Update multiple rows in a single column in MySQL?
- Concatenate data from multiple rows using GROUP_CONCAT() in MySQL?
- MySQL query to check if multiple rows exist?
- How to order MySQL rows by multiple columns?
- How to get multiple rows in a single MySQL query?
- Combining multiple rows into a comma delimited list in MySQL?
- How to obtain multiple rows in a single MySQL query?
- How to Autofill Formula When Inserting Rows in Excel?

Advertisements