借助以下语法,可以在同时插入多个记录时加快MySQL的插入速度
START TRANSACTION insert into insertDemo(yourColumnName1,yourColumnName2,...N) values(yourValue1,yourValue2,....N),(yourValue1,yourValue2,....N),.......N commit
让我们首先创建一个演示表
create table insertDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAge int -> );
同时插入多个记录。查询如下-
START TRANSACTION; insert into insertDemo(StudentName,StudentAge) values('John',21),('Carol',22),('Bob',21),('David',24), -> ('Maxwell',25),('Mike',22); Records: 6 Duplicates: 0 Warnings: 0 commit;