您的位置:首页 > 其它

插入数据简单测试

2017-06-06 17:08 127 查看
版权声明:/*Copyright © AskTommorow & BianZhongMing , 转载请注明出处.*/ https://blog.csdn.net/AskTommorow/article/details/72885268
--Create table
if(object_id('testa','U') is not null) drop table testa;
create table testa (
id int not null identity(1,1) primary key,
val varchar(200) not null
constraint testa$BPK_AK_Key unique nonclustered(val));

--Query
declare @v varchar(200)=newid();
if ((select count(1) from testa where val=@v)=0)
insert into testa(val) select @v;
else
return
---------------

select count(1) from testa;

select top 10 * from testa;
/*测试:
30000iterations * 1threads 07:16s second/iterations=0.0100
10000iterations * 3threads 03:21s second/iterations=0.0124
5000iterations * 6threads 02:35s second/iterations=0.0191
1000iterations * 30threads 01:41s second/iterations=0.0574
*/

truncate table testa;

----------------------------
--Query(merge)
declare @v varchar(200)=newid();
if ((select count(1) from testa where val=@v)=0)
insert into testa(val) select @v;
else
return
--10000iterations * 3threads 03:00s
--效率提升

--Query
declare @tb table (v varchar(200));
insert into @tb values
(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid()),(newid());
select * from @tb;

if ((select count(1) from testa where val=@v)=0)
insert into testa(val) select newid();
else
return
---------------

--增加线程数量,单节点速度减慢,总进度加速。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: