
- 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
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)
- Related Articles
- MySQL INSERT INTO SELECT resulting in multiple rows inserted at once from another table
- Can we use stored procedure to insert records into two tables at once in MySQL?
- Insert more than one element at once in a C# List
- Count rows having three or more rows with a certain value in a MySQL table
- In MySQL, how can I combine two or more strings along with a separator?
- How can I loop through all rows of a table in MySQL?
- How can we combine the values of two or more columns of MySQL table?
- How can I create a stored procedure to insert values in a MySQL table?
- Can I play the same sound more than once at the same time with HTML5?
- Delete more than one rows from a table using id in MySQL?
- How to multiple insert or batch insert at a time in MySQL query?
- How can we insert data into a MySQL table?
- How can we fetch one or more columns as output from a MySQL table?
- Can we insert records in a MySQL table without auto_increment values?
- How can we combine values of two or more columns of MySQL table and get that value in a single column?

Advertisements