码迷,mamicode.com
首页 > 数据库 > 详细

SQL批量删除与批量插入

时间:2016-11-29 14:13:21      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:操作   arc   测试   not   方法   1.2   values   tab   union all   

批量删除:

DELETE FROM MyTable WHERE ID IN (1,2);

批量插入:

INSERT INTO MyTable(ID,NAME) VALUES(1,‘123‘);
INSERT INTO MyTable(ID,NAME) VALUES(2,‘456‘);
INSERT INTO MyTable(ID,NAME) VALUES(3,‘789‘);

第二种方法,使用UNION ALL来进行插入操作:    
INSERT INTO MyTable(ID,NAME)
SELECT 4,‘000‘
UNION ALL
SELECT 5,‘001‘
UNION ALL
SELECT 6,‘002‘ ;
据说要比第一种要快!

第三种方法  
INSERT INTO MyTable(ID,NAME) VALUES(7,‘003‘),(8,‘004‘),(9,‘005‘);

Example:

表: leafjob(
leafnum INT NOT NULL PRIMARY KEY,
machine VARCHAR(15) );

删除:delete from leafjob where leafnum in (1,2,4);

插入:

INSERT INTO leafjob (leafnum, machine) values(1, ‘r1leaf3‘), (2, ‘r1leaf22‘);

insert into leafjob(leafnum, machine) select 4,‘000‘ union all select 1,‘r1leaf3‘ union all select 2,‘r1leaf22‘;

insert into leafjob(leafnum, machine) select 1,‘r1leaf3‘ union select 2,‘r1leaf22‘;

注:性能问题需要具体测试。示例在MySql下测试过,version: 4.1.20

SQL批量删除与批量插入

标签:操作   arc   测试   not   方法   1.2   values   tab   union all   

原文地址:http://www.cnblogs.com/liaojie970/p/6113104.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!