您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

SQL批量删除与批量插入_MySQL

2024/3/28 17:28:05发布9次查看
批量删除?:
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
作者:zhenjing.chen
出处:http://www.cnblogs.com/zhenjing/
未注明转载的文章,版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
绿色通道:好文要顶关注我收藏该文与我联系
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product