- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to fasten MySQL inserts?
You can speed the MySQL insert when you are inserting multiple records at the same time with the help of the following syntax
START TRANSACTION insert into insertDemo(yourColumnName1,yourColumnName2,...N) values(yourValue1,yourValue2,....N),(yourValue1,yourValue2,....N),.......N commit
Let us first create a demo table
mysql> create table insertDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAge int -> ); Query OK, 0 rows affected (0.72 sec)
Insert multiple records at the same time. The query is as follows −
mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> insert into insertDemo(StudentName,StudentAge) values('John',21),('Carol',22),('Bob',21),('David',24), -> ('Maxwell',25),('Mike',22); Query OK, 6 rows affected (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0 mysql> commit; Query OK, 0 rows affected (0.14 sec
Display all records from the table using select statement. The query is as follows −
mysql> select *from insertDemo;
The following is the output
+-----------+-------------+------------+ | StudentId | StudentName | StudentAge | +-----------+-------------+------------+ | 1 | John | 21 | | 2 | Carol | 22 | | 3 | Bob | 21 | | 4 | David | 24 | | 5 | Maxwell | 25 | | 6 | Mike | 22 | +-----------+-------------+------------+ 6 rows in set (0.00 sec)
- Related Articles
- MySQL Count Distinct values process is very slow. How to fasten it?
- How to write a MySQL stored function that inserts values in a table?
- Multiple Inserts for a single column in MySQL?
- Perform multiple inserts with INSERT INTO SELECT and UNION in MySQL
- How to prevent multiple inserts when submitting a form in PHP?
- Batch Inserts Using JDBC Statements
- Batch Inserts Using JDBC Prepared Statements
- How to connect Java to MySQL?
- How to take MySQL database backup using MySQL Workbench?
- How to change MySQL timezone?
- How to use MySQL decimal?
- How to rearrange MySQL columns?
- How to restart MySQL server?
- How to merge MySQL results?
- How To Check MySQL Version

Advertisements