首先我们建立一个测试用员工表

---创建一个测试的员工表---
create table Employee(
EmployeeNo int primary key, --员工编号
EmployeeName nvarchar(50) null, --员工名称
CreateUser nvarchar(50) null, --创建人
CreateDate datetime null, --创建时间
)

执行后结果:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcAAAABuCAIAAAA/JlQOAAAgAElEQVR4nO3deVxTZ74/8Pua3nm106m1d2bq2M70djrTmXp99XamM3Z6p+2vdWLrVpFWxaBVSxGQhn0Lm4EAskXEIKKGRfYSDCD7GhbZhQAJm4EQIJAQliQECCQkgfP740gMEBCD0orf9+v8c3gO54Tn+Z4POXmSk/+Q6lJYWFhfX89ms6lU6vDw8JLW69evW1pampiY2NjYtLW1jY2N6dwJis1mNwEAwGb0H3oEKIvFCgsLMzExMTc3DwoKam1thQAFADyD9AlQqVTa2NiIZqiJicnVq1ebmpogQAEAzxo9AxR9Hurv729mZmZiYhIeHt7W1gYBCgB4pugfoFKpdHBw0MPDw9ra2tra+urVqxCgAIBnyroCVCKR8Hi8/v7+/v5+gUAAAQoAeKasK0DXAgIUALBZQYACAICeIEABAEBPTzxAu7u7mQAAsBk98QAVi8UiAADYjB4SoImJiQUFBUUAAACWWS1A+Xx+HQAAgBWsFqDruXIHAIBNDwIUAAD0BAEKAAB6ggAFAAA9rRagYrFY8GwQi8Ub3O8AgE1gtQAdGRnp7u4eHBzkb16Dg4Pd3d0jIyMb3O8AgE3gIQHK5XJVKhWyealUKi6XOzw8LNkUxsfHN7iAAHiWQYCquFwuh8Pp2RQGBgY2uIAAeJZBgKq4XC6fzx95+qH3Zt3gAgLgWbauAFUo50rbRvKbhTqXXIYwrkh4M3/p0syZ2siIXB0aoCPLXgMVCARdXV1sNrutra11MQajmcvtffJD88j4fD4EKAAbaV0BOj6txCey7BM7nVO6nVO6nX/odo7sxlG6LSjdFpRu04juL9y6/+28aPkQx6RkC1YPtdHR0fLycoVCofmJQqEoLy8fHR19bMG5YKUAbWvrLiurZzKZ9fX12p/cqqysjE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Zw1J9fi0xRP1OG/6oN/b++dUKkX/QFey4x+c4vLaHvoGw6cC3EwEbiaCggDVol+AtiVecfryfz8zPBrcMjCp/KmdUj9+gPaXlV75dsd7737qWFh2b/yJ3G1kw0GAQoCiIEC1qGQKcVflna6BMdkj3PdA3N1WV5SeX1bJlSlUenxe78l6nIU+r0JkXCaj6x5XpOPjcSuZFAjaKlLTbhe1j43JNslXEEKAQoCiIEA3OSj0JwGqDuoKBQG6yUGhPwlQdVBXqKc+QBUKxcjIyNzcxt9U9+kwNzc3MjKiUDyhm/I8o6DqoK5QU1NTEsmKtx55CgJ0fn7+WX4isBZqtXpe100Rgd6g6hCoKwRBEGRubm6VSngKAhQAAH6aIEABAEBPEKAAAKAnCFAAANATBCgAAOgJAhQAAPQEAQoAAHqCAAUAAD1BgAIAgJ4gQAEAQE8QoAAAoCcIUAAA0BMEKAAA6AkCFAAA9AQBCgAAeoIABQAAPUGAAgCAniBAAQBATxCgAACgJwhQAADQEwQoAADoCQIUAAD0BAEKAAB6ggAFAAA9QYACAICeIEABAEBPEKAAAKAnCFAAANATBCgAAOgJAhQAAPQEAQoAAHqCAAUAAD1BgAIAgJ4gQAEAQE8QoAAAoCcIUAAA0BMEKAAA6AkCFAAA9AQBCgAAevr/rnaBDXI4pgwAAAAASUVORK5CYII=" alt="" width="382" height="93" />

那么假如我们要批量插入10000条数据,应该怎么办?

这里有四种方法(普通循环,事务循环、批量插入、cte插入)

1、普通循环插入(while)

/*******************************************
***普通循环(插入数据10000,执行时间:1283毫秒)
********************************************/ --开启开关(记录sql语句各个阶段所消耗的时间)---
set statistics time on;
--声明两个变量---
declare @Index int;
declare @Timer datetime;
--对两个变量进行赋值----
set @Index = 1;
set @Timer = GETDATE();
--当循环小于1000次执行添加语句---
while @Index <=10000
begin
--执行添加的语句--
insert into Employee(EmployeeNo,EmployeeName,CreateUser,CreateDate)
values(@Index,'员工'+ cast(@Index as CHAR(5)),'system',GETDATE())
--设置循环次数加1
set @Index = @Index+1
end
--获取执行的毫秒数--
select DATEDIFF(MS,@Timer,GETDATE()) as '执行时间(毫秒)'
--关闭开关(记录SQL语句各阶段所消耗的时间)
set statistics time off;

执行普通循环插入10000条数据,大概需要1200多毫秒,结果如图所示

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMEAAABaCAIAAACOgaVLAAAYZUlEQVR4nO2ceVhTd7rHqbbzh30e9Hlqp95aZtrnPtfbO9br2CJ2prbWXooLUmrbUbSdsXVFq1IxKtCKQSiLsgh1iBB2ZN8CSUBAlhD2NQQCJIGQHELIahYSlC3n/vEbzhyyEQWNwXyf95/3nDfn9zvn9yHnm5eT2ClssmlxsrP0BGyyetlJlqnkcrmlr+2LIjvmMpVIJLL0tX1RZPdo2Umj0QwODtoYemayg5edpqenh4aGhoeHoWUhgUBgaUgW0LJliMvlWnr1l0AcDofL5VoakgWky9DMrHZEOjEsVhsMjkjdx1UzhnVDLJ+yCC4GBRjSv5dJJBKBQCAQCEb0xOPxhEKhRRbAtPh8vvUxJNdMXU7vPhnXbjB+uN3+l7PtH5zUjbiSUdPrqtVqZ2dndTbOzs5qtdqlxAeGYeMMDQwM1NbW1tTUkEgkIkolJSUZmdnNza0WWQDTsmKGAktFUXWaqDpNVLUmKlHjHac5Gac5Gac5cUfz91ua76LmxQ7vgQUZolAoLi4uYrEY2SIWi11cXCgUyjNjqLl5qLy8b3x8XKlUIhvlcjmPx4spIhQ3ND7bK2+WrJghTBbLr4DrV8D1y+P64bln47gHwri7/AzHXw7Q49IXYKikpOTNN98cHf132ejo6JtvvllSUqJTWVxcfNykYmJinoyh+nrOvXtsUDM5OSnRTHPH4SHFbD1THhBbkkeut8gCmJZVMqTSTIWmd98pZWdQeRlUXjplOIbQmXSfHUvihWTwgtI4XpGt1xKZIRm84LtcbNLgD9c6P91TFBfXbWJR29rawsLCfHx8FApFaWlpbGxsbGxsSEjI6tWrT58+DdLU1FS1Wg3DMBaL/eMf/3h6To6Ojjqpm5vbYhianZ1VKBQCgaCfK2ji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DfgoPimzssvTbWElk5+UvYp35aDInFkopqysACfWoDDAkEo6z2yvSrf/vi+K/+GS39EgmfS68n3Lrk4e68dZerh98NQnsL9wFPohLKVDxGY03Mt/+344MDmGhcWT8dsvzyWEV09/Z1dXWZuZoWY8i8PrUeQ1LFUHtZ8S+fvvHp9YiyngGZSjhCZ9wPcXEJSyjtGZDxWktTA132BNzntIwgB0EZ8CrLL49VxNL2qZ8WQ+b1qXUZYtdl4P2PbtkfhKtm0EakozIVl15dHbXf2Zdc2MIflcnZLeQiX5cvohpK6aK5g6AMeA7H4stjFbF8PXUXMf5nzDcHLl0s7KQJHvBlKqFMxe+lNN8+9O63+PgaFkc21l2TcvvbP/3tNi0/KyE2NS2wqHeeASeJFn99X4RYtp6akf3Tyc8/dPif/cfDwq+HhQeHhUdn3CPWdQ6Uxx745uDJS75Xw65jLp35+pvDt8p51LLMyFDMobM/BYfdCA7zO3vyh18iMwh0yy+PVcTSeupJGG7Px+CzEur7l4qgx/DU7SXRSRFn0ytkqhGZqj7lPOawk+PWf8duz+Bg0vAINFxxY89hVyfHrU6Orv9wuUHpg6RCmaqz9Hak578qv7yamdbAt/jaWEssrad+KgKe2sH27MfzGld8f9m/f7+Zq2l79sMWBsL27IctFhtL66mfisz21LawTCytp34qMttT28IyYU2eOuVu1qhYLpAoRoQyoVTJFz2wpc9Dirni+9ieWqVSjT9DqVQqqVTa2trqcehQeEQEkUT++JMdbPbg8RMnbenzkF719+dyueYyRCRXKFWqSQupoqKivb2dw+Hk5OQoFApb+pyk5t/IYEt9V9qm5SQbQzYtVjaGbFqsbAzZtFjZGLJpsbIxZNNiZWPIpsXKxpBNi5WNIZsWq/8Hf+/od/D45F8AAAAASUVORK5CYII=" alt="" />

2、事务循环插入

/*******************************************
***事务循环(插入数据1000,执行时间:460毫秒)
********************************************/ --开启事务--
begin tran;
--开启开关(记录sql语句各个阶段所消耗的时间)---
set statistics time on;
--声明两个变量---
declare @Index int;
declare @Timer Datetime;
--对两个变量进行赋值----
set @Index=1;
set @Timer = GETDATE();
--当循环小于1000次执行添加语句---
while @Index <=10000
begin
--执行添加的语句--
insert into Employee(EmployeeNo,EmployeeName,CreateUser,CreateDate)
values(@Index,'员工'+ cast(@Index as CHAR(5)),'system',GETDATE())
--设置循环次数加1
set @Index = @Index+1
end
--获取执行的毫秒数--
select DATEDIFF(MS,@Timer,GETDATE()) as '执行时间(毫秒)'
set statistics time off;
--提交事务--
commit;

执行事务循环插入10000条数据,大概需要400多毫秒,结果如下所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMsAAABjCAIAAAC61mPnAAAVp0lEQVR4nO2da1RTV6LHUcf5oHeh92pXXUWmetcdp3Nbx9IBvHctH1cvohUp7czcGau2WtSRooAErECrHgoVkIcGNbGCgAgSQCXkwVME5GF4h/BKeIQkhBASYk4i0fI898OW00NehEcI4vmt/WWfszl7n+yfOf+zcxKt8vLyWCwWl8ulUChSqRTWh1QqZbFYZ86cOXbsmLe3d2Jiot5mXC63DgdnMlamGAbDsEwmKyoqys3Nzc3NZbFYuGE4JmKqYaaAG4ajC24YjnnBDcMxL7hhOOZlLg2TSCQiHJzJ/GpYampqTU1NAw7OnPLasK6urmwcHDPw2rDZXBxxcIyAG4ZjXnDDcMwLbhiOeXltmFKplL8dKJVKS7/mbxevDevv7+e9HfT391v6NX+7+NWwzs5OjUbzy+JFo9F0dnbihs0zvxrW1dU1MjKCLF5GRka6urq6u7stvco9N0gkEkvLYxJvnWECgcDSbswBfD5fIBBYWh6TeOsM071KyuVyiUQikUh6dBAKhbP8rNZMiMVi3DCTGB8fHxsb09o4NjY2Pj4+530ZMozL5ZaUlBQXFzMYDDoGGo2Wep/CYlVbZGKMgxtmKqWlpc7OzjKZDN0ik8mcnZ1LS0vnvC9DhrFYXfn5rS9evFCpVOhGpVIpFApjs6jZFZXzOyMmgRtmKjQa7b333uvt7UW39Pb2vvfeezQaTatldnb2CaPExsYa78uQYeXl/Ly8DtBmaGhIrhkRvEC64LFynjKYRM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3lErVYPDAxUV1cf/PLLqOhoOoO5fcfOjo7OEyf/iVcXQvXCxYsCgWBuDKMzC1Rq9ZCFKCgoqK2t5fP56enpMAzj1QVSne4l0phhFvlVAZzFB24YjnnBDcMxL7hhOOYFNwzHvOCG4ZgX3DAc8/L/+USzSvlI1KMAAAAASUVORK5CYII=" alt="" />

3、批量插入

/*******************************************
***批量插入(插入数据10000,执行时间:33毫秒)
********************************************/ --开启开关(记录sql语句各个阶段所消耗的时间)--
set statistics time on;
--声明一个时间变量---
declare @Timer datetime;
---对时间变量进行赋值---
set @Timer = GETDATE();
---执行批量操作的sql语句---
insert Employee(EmployeeNo,EmployeeName,CreateUser,CreateDate)
select top(10000) EmployeeNo=ROW_NUMBER() over( order by c1.[object_id]),'员工','system',GETDATE()
from sys.columns as c1 cross join sys.columns as c2
order by c1.object_id
--获取执行的毫秒数--
select DATEDIFF(MS, @Timer, GETDATE()) AS [执行时间(毫秒)];
--关闭开关(记录SQL语句各阶段所消耗的时间)--
SET STATISTICS TIME OFF;

执行批量插入10000条数据,大概只要33毫秒,结果如图所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALIAAABHCAIAAAAst4qVAAAW80lEQVR4nO2da1gTZ9rHEfWLvS70uqxX3SK79sPbd9+3damtxe6KWl0XrUrpdltF665bPCEVEcSKtOogyEkJDYtEDuEo51OABIVwCuF8DAGEBMhhCCFHE0LCISSZ98O8TIcQQlCQFPlfz5d75s7zzDzPj8w/d2aChfgNkEwmk69qIbJgvAESCoXLPc+/MVmoVKqJlSuVStXf37+KxUJlMTU1Ba1cTU1NDQwMsNlscEWIz+evYrEIgrHgcDjLvaCLIBaLxeFwlh8LjVY3KBlji5QGG0uofM5RdrP1m0imfp0Lb1wwFrMvImKxmM/n8/n8wVnicrkCgeD1zP6CxOPxzAILmUr9Y0rHxegWg+37yJY/X2n55KJ+iy4cMr5UOp1Oq9XqbdRqtTqdbhFAmKm5sOjt7a2qqqqsrCQSiUUoFRYWpqZlNDQ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pf+Sw70+2u3bsP37aLby7FZTxBvtJMT6ux//rw12ffLzrv7+6Eh9bArKWewHMsy2d5ZSyamMDPlu/+a11a9ccObPYWBiznIz6jgTXbYcCMU87e6XtFWlRF37nEd812FUR/qPnzc89Mluk4iEpMejIzXs3M0uWewHMsy2d5dRMKqWCvuYueuyt/d73FxsLY5ZTKOKxGdQ2Vs+gZEg6UF+UcNv+qyAKp7mf0/m8r/H50KD0xbC0Ne6i6727j1OZy78GZtiW2nJOQFB5pOMdzGJjYarlHGwi40NP/c/32BaQJpzeKBYJ+rLvOl2+4ZtE4C3/GphhW2rLuVRYgCB4zcu7ag7LCTd2G5kQd+u666WvndNJ/cIBqUIgVfA4THpJTPidk6e+DQyIaWhd7gUwz5aesVSWE9ZSYSESiUsrKL1Gq5w9xId+rof/+tUpD1x15XMpW6AQSBXc7rrKiO/+uv+TE95Y3NMeOrj8a2CG7Qf3q0ta5VwqLEyucnKbiiPuHvzdv/GMil5ko0wg7Ux233/N41Zg+fKvgRm2pa5yLhUWJlc5ZX2NhXm39h4JqSHShNMbRwRSSWPMxZ/8/DwyWcu+BmbYVqDlBJntDVn3L+Aqy+lDAulwR2Vi5Hf/+20kLSc9Liop2T+/SyCVC6Ssont/v3Hz9s9E4eJO6MpoK9Bygn0d9Zn3vr106frPQGDIvZ98r15yuRRRClKfpmGCvU9duRYYEhoY4nvl4vc/Y1IJ9OVfAzNsS205JyGoJcc7Nj2uxuTnVubXvJZzEGSXhn5x+pjdrk/tPv/motsTJnNIJpAq2oojMa52uz612/Wp3Ve305Jrecu+AObZXsJy/h8M6U+MNL6OSQAAAABJRU5ErkJggg==" alt="" />

4、CTE插入

--/*******************************************
--***CTE插入(插入数据10000,执行时间:40毫秒)
--********************************************/
--开启开关(记录sql语句各个阶段所消耗的时间)--
set statistics time on;
--声明一个时间变量并赋值--
declare @Timer datetime = GETDATE();
---将要添加10000条语句组合成CTE模块---
;with CTE(EmployeeNo,EmployeeName,CreateUser,CreateDate) as (
select top(10000) EmployeeNo = ROW_NUMBER() over (order by C1.[OBJECT_ID]), '员工', 'system', GETDATE()
from SYS.COLUMNS as C1 cross join SYS.COLUMNS as C2
order by C1.[OBJECT_ID]
)
--执行CTE插入语句---
insert Employee select EmployeeNo,EmployeeName,CreateUser,CreateDate from CTE;
--获取执行的毫秒数--
select DATEDIFF(MS, @Timer, GETDATE()) as [执行时间(毫秒)];
---关闭开关(记录sql语句各个阶段所消耗的时间)---
set statistics time off;

执行插入10000条数据,大概需要40毫秒,结果如图所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALkAAABlCAIAAACeM9VfAAAYG0lEQVR4nO2de1RTV77HEdt/7Cx13dalU2TG3jXtmns7jmOnxc7U6ui1aFHKtLaK1FYHfFArWhFbpBUPgvKQh0FN5BHCQyCGV4AEhYAI4f1KiCCER0gCBMiDnIQEJUDO/WOX05NAQlRe4vms/c8v2Tn75OwPOV825wQrGIZhGL53715VVVVrayuVSu3v74efg9bW1nqcxYgV7gqOheCu4FgK7gqOpcy8KxKJRIyzGDF2JTk5uba2loODMwkDVzo7O7NxcExg4MrznHpwFj24KziWgruCYym4KziWYuCKUqmUvRwolcr5Pe4vIgauDAwM8F8OBgYG5ve4v4gYu9LR0aHVap8sXrRabUdHB+7KM2DsSmdn5+joKLJ4GR0d7ezs7Orqmu9V0JlBIpHgrswWwBWhUDjfszwDCAQCoVC4QF0ZG9d3y4e7pJopm2BA80ioae4yblKlbi5tMA9wZfI5SCaTSSQSiUTSPQmRSPScfyObJXp6ehauK0qt7sekxmNRdVO2/9yo+8fJur8fM25ROb3m50+v14+Pjxs9OD4+rtfrZ8AOQ0y50tra+uDBg+LiYgaDkYshJycnOYVaVVUzZ1NiOS+AK/55AxGl2ohSbcR9bQRZ6xmlPRalPRalPXpL+8017cEIg7bVs3VaV0pKSuzt7aVSKfqIVCq1t7cvKSmZMUcmMOVKVVVnfv6joaEhlUqFPqhUKkUiUWQWPbu8Ys6mxHJeAFe8Utt8MoQ+GUKfNK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d9e28SLOb/V6/KMf65Mk20Hkzmtv5z+Ye8nH9rt/eZXV2iEfWevfOBVmMCBkzlyPy/Hg2cvuNHmf2IWYJuXbPsEQYpuOPqGz7Qr02Tb2r7kzJsObv4O+792OXkEuBJz6/x+r4DtgVzQJyLwsIvXxb23xPM+MQuwzUu2nS1XuoTi/ce9TGTb/gR21UXXk7u87xz2hU6d+9WVm9dOHTh3afc1PuhmVOIN265T7sz9uu1sudLbLwu9UzJltk2qbiKmRdj/788no+oDE6/jrjxD23/k1Nyv286WK2aybRzj3iWvHRvOFv5CFxMphJNnXTf+wiGWKW5cO33gnD/WFZdzl/Zca5v3iVmAbV7WbWftc8Vktu2OTLx1cNPvVv7+v1ev+5+1tjZvrPqv363btMmH7R/q+6XXZbsL5aBn4AWng14+BxMV8z4xC7C9JNlWRi6qv3KNeOIS8Zgf8dDRg598umXd3qvfJ7UR70R9eybwY/fsWxzlbY7gvLvLN2eCT+bO/8QswPbyZNvfWhQmrySzK3709XNwOrzXO/hbb5/tTh4HfNOD2PM/MQuwzUu2HUGQunSvmNTYMotvYpoe89kW22LTqT8H+++5xo+pGkzmqK5Trh/92u7tv9q9/Ve7t7++fpTyaN5nZWG2ecm2swLItmttbc/h1yTMTnskluPXJODNooZfk4A3S9u8ZNtZwfJsi7dna/OSbWcFy7Mt3p6tLbZsa2tr6xmRcrt+MLlBmVgrT+HASXUKvJyRchazrVqtHppD1Gq1XC6vqan591cHoMCw1Czmxg+3cB51HDh8DC9npHQ9cmzms20us0ClVo/MEwUFBXV1dQKBAPxHbLycwZLD4cywK/NyjyrOwgR3BcdScFdwLAV3BcdScFdwLAV3BcdScFdwLAV3BcdScFdwLAV3BcdScFdwLOX/AanyCup1+TnwAAAAAElFTkSuQmCC" alt="" />

最后我们查看一下,批量插入10000条数据的员工表

小结:

1)按执行时间,效率依次为:CTE和批量插入效率相当,速度最快,事务插入次之,单循环插入速度最慢;

2)单循环插入速度最慢是由于INSERT每次都有日志,事务插入大大减少了写入日志次数,批量插入只有一次日志,CTE的基础是CLR,善用速度是最快的

那么,假如我们要批量删除我们插入的数据,怎么办呢?

批量删除有3中方法(循环删除、批量删除、truncate 删除)

1、循环删除

--/*******************************************
--***循环删除(删除数据10000,执行时间:20毫秒)
--********************************************/
set statistics time on;
--声明一个时间变量---
declare @Timer datetime = GETDATE();
--删除语句--
delete from Employee
--获取执行的毫秒数--
select DATEDIFF(MS, @Timer, GETDATE()) as [执行时间(毫秒)];
set statistics time off;

删除10000条数据,所需的时间大概为20毫秒,如下所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALYAAABeCAIAAAABhXm8AAAYIklEQVR4nO2de1QTZ97HEdt/7HvU97SeukW29pzdnp7tutbdFtt6W30tWpWyvSlaWy14oa5oRWyRrToIykVuQSVyCYFgJAaRAAkKATGEa7gkRBACJCQBArmRCwnKJXneP2aZDoGEqBEQ53t+//xmnjzPZJ4PM9/8fGZ00g8YYi8nP2huGUSpqKiourq6tbWVQqH09fVpn0EymUyK6UWWk21EyGRybW0tF9NLLFuICIXCXEwvvWwh8iz3F0xzRhgimKYQhgimKYQhgmkK2UJEo9EoXw5pNJqZnojZK1uIyOVywcshuVw+0xMxezUFIh0dHUaj8fHcldFo7OjowBCxoSkQEQqFIyMjYO5qZGREKBR2dnbOdA3TMZLJZBgiDhaMiFgsnunJdYBEIpFYLJ5diIyazF2qwU6FYdIQyQ0PxYbmTstQaIanEwLbghGZeKNRKpUymUwmk3VNkEQiecZ/t3pO6u7unnWIaIzDv2Q0HkqsmzR+vFL3ydG6fxyyjMS8HtvTZjabTSaTxUaTyWQ2mx0AxXhZQ6S1tfX+/fulpaV0Oj0fpby8PPINSnU1x+Ez8eyavYiEFMhjy4yxZcbYe8ZYgtE/0Xgo0Xgo0XjwmvH7OOPe2HGxwb91SkRYLJa7u7tCoUC2KBQKd3d3FovlMDTGZA2R6mphYeHDgYEBnU6HbNRoNBKJJD6HlltR6fCZeHbNXkQCMtuCssVB2eKgLHFQsvhoonhnhH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ufwb3wcl9Pt//fNm/aObnYxbG9NjV0SGDuq+9tomffHpDwAWHX0Ws29XrnN7Ue/zIQmlKtZrM7U+m5f12ZN0/TpdDceE7T178KKA4naslc1XBAR57T57xoc78fMzCmE67+hiAkiseZ2McjYjddlV2NTPtiOdf1p3nBoWc2hUQuimMB++KDdu/J+Dc19ekMz4fszCm064+L0Q6xdJdhwOs2VUk0orvnwk99emaHT+kiYIvHtt96vz2OAG862rcuBQLdFwm3py26urzQqSnTxl1k2W7uprOagqLC9+1z/v9fZlhZfK4OAwRe2PXgWPTVl19XohMXV2t778ce2zLV/tX/EjBcXUZXN3VuOO7T4WgEdlz6vyOuLYZn49ZGNNZXX1uVxGb1dWMKsmV6MPrvzy+5Zes88zudK6OzNWRSBe/CbjgdqYCbhN2xnNvQNBeknrG52MWxly3q+UPk1LjNn6y6/9Okk/ShERkez7hhxNh63xzr3E117mi0757vj8RcTR/5udjFsYct6tERuH5o6sX/c/qD77x/yrw0r7ASz+eueJ3ve3q3bJfzgZv89z/dWDED4FBmzz9dp+9Fc6e+fmYhTGddnUIgLpbAcmZKeV2P+NjFyI27GpSXuGvvm5/+8jtz3/7b7y32n0DVBlWJL9MvHzwu7Ht310+SHw445MxO2M67epzEWxXl7m6nsIWAzyfeChVYYsBsLAV2GIALKaI6bSrz0X2V1exeLqYTrv6XGRndRWLp445YlddXV39Y29cr+8nN2hItaobXG1GnRpLHZI63q7q9fqBaZRer1epVBwO51/f7obCojNzGKs+Xs992LF7/yEsdUjqfeCQw+xqPqNIp9cPzZCKiorq6upEIhH8HyJjqQNTLpfrGERm5IFNTDMrDBFMUwhDBNMUwhDBNIUwRDBNIQwRTFMIQwTTFMIQwTSF/h9xjcsk3yeh3wAAAABJRU5ErkJggg==" alt="" />

2、批量删除

/*******************************************
***批量删除(删除数据10000,执行时间:23毫秒)
********************************************/ set statistics time on;
declare @Timer datetime = GETDATE(); SET ROWCOUNT 10000;
while 1 = 1
begin
--开启事务--
begin tran
--执行删除--
delete from Employee;
--提交事务--
commit;
IF @@ROWCOUNT = 0
break;
end
set ROWCOUNT 0;
--获取执行的毫秒数---
select DATEDIFF(MS, @Timer, GETDATE()) as [执行时间(毫秒)];
set statistics time off;

删除10000条数据,所需的时间大概为23毫秒,如下所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAALIAAABoCAIAAADaTT12AAAYkklEQVR4nO2de1QTZ97HEdt/7DnoOdZT3yK79o+375639bW2Ft31Vl2LVqXsdreK1q14RysiiBXZqoNQBZTQsErkEi5B5CYQIAEhcgnhEu4hgpBAbkMIIRdzIUG5JPP+MWU6hCRGDJLifM7zz2/yMDN5no/JN09motMIivLyciaT2dPTk5WVJZVK1VOhUCiXL1/28fE5depUXl4en89XW6anp6cV43eLk+1aqNXq0tLSoKAgHx8fHx8fMpksEokwLeYlL6eFWq2uq6s7fPgwbEZWVhamxbzkpbWQSqVMJvPMmTM+Pj5nz55NSUnBtJh/vLQWarVaJpNVVFSUlpaWlpYymUxMi/nHTLSwBUyL3zWYFhhmwLTAMAOmBYYZZksLiUQCYvxuMa9FRkZGc3NzO8abihkteDxeIcabjRktXuW9A2N+gGmBYQZMCwwzYFpgmMGMFiqVSv5moFKp5nr8HRQzWgwNDXHeDIaGhuZ6/B0U81r09fXp9frn8xe9Xt/X14dpYQnzWvB4vPHxcWj+Mj4+zuPxBALBXC8n2geJRIJpYQdgLYRC4VxPqB3g8/lCoXDutZgwGPsVIwKZzmzjD+meCHVdAtMmU429zom3DqzF9DcRuVwukUgkEkn/NEQi0St+TzRLiMVih9BCpR/7Mb3jRHyL2Xb4dsufz7R8dsK0xRcNWJ8qo9FoMBhMNhoMBqPRaAcRpmJJi56enurq6qqqKgqFUoyiqKgo434Wk9lk39G3C46lRVjJUEyNPqZGH1OpjyHqA+P1J+L1J+L1x+/q//WL/mDMlLYlsOeFWtDpdA8PD5lMhmyRyWQeHh50Ot1uOkxiSQsmk1dW9mR4eFij0SAbVSqVSCSKLSAX1tXbd/TtgmNpEZTJD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b/8iFyKnNwPwZc/MI/u0UpH1BSbuy8eO1idtlcT4BjttmLnBOjOqW0t7mTnXhpS9DP9tbCSuSUDEoFXHZNZ3/vwFOpUtXbWJR/adPOyFpKQ/fjJ72NTwb6lU8Hla1JJ3yvXb2bwZ37OXDANtuR8zkEVdz2vIKztxY2R87BjqrU29/977e3WeWdT3/dKJdJe3Ovep26EJJGFs/9HDhgm+3IOVtagCB4LjCo2kLkRJqou7qAcOGb7XvCSwUtIq1UqRULueyyhJgr+/Z/ez08gdk61xPgmC0za7Yi5+xqIZPJyyvpPVZXOft5XZUZESF+Rzedyariy0SwKF31VbHf/XXLZ3uD8ITSbjY493PggO0Hv7Ozuso5W1q8cJVzUK5qT/c/9v3hLf7ZLUrtwJRHVVLlY5LflnP+l65XzP0cOGCb7VXO2dLC+irngBhkpZ7c9y//YxEPSp8M9Cu1g1M6aKRKRWPCiX+Hhvpn8+d8DhywzcfIKezuoeAPbvU+FJ6R1sQXTm7nVqfGpZHCCjqlSrVUyS++9vcLFy//RBma8zlwwDYPI6ewvbz0p/XLXNb/1ef8+chb1yNvRcTcSaBxa0tIuIig/WfOXY+Muh4ZcubE4Z9wGWT23M+BA7bZjpyjENTyICgxM6nW5vtWbNLCSuTktJRlXXTfutF97ee/tvVbPLxj6yu7ZG0lt3G+v2782+X7pDrxnE+AY7bZjpyzAhw53bAv1metyeTYF+tYm9awL9axZqbNduScFWxf5cTazNpsR85ZwcZVTqzNuP2+I2fqvcwBmUoiV/dLlVKFRjz0FCvtUtoncmq12uHXiFarVSgUTU1N3vv334qOLqZQN23e0tvbd+z4Cay0S3n8xIlXipzF1HKNVjs6R5SXl7e0tPD5fPg/mcVKO5bt7e0z12JObjbEmEMwLTDMgGmBYQZMCwwzYFpgmAHTAsMMmBYYZsC0wDADpgWGGf4fieFXp5nJlkcAAAAASUVORK5CYII=" alt="" />

3、truncate删除

--/*******************************************
--***truncate删除(删除数据10000,执行时间:3毫秒)
--********************************************/
set statistics time on;
--声明一个时间变量--
declare @Timer datetime = getdate();
--执行truncate语句--
truncate table Employee
---获取执行的毫秒数---
select DATEDIFF(MS, @Timer, GETDATE()) as [执行时间(毫秒)]
set statistics time off

删除10000条数据,所需的时间大概为3毫秒,如下所示:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMIAAABuCAIAAAD6XVvzAAAYPklEQVR4nO2de1QTZ97HEe0/9hz0nNZTt8iu/adn37frWnetdrdeal8XrUrZ7bYWrbsq3tAKVkq3ylYdhKqgQMMqkUsIgkgAgUASUAJCCJBwDxGEBHIbQsjVXEhAAsm8f8wyHQKJEcIlMJ/z/PObPJmZzPMx883DzOjR3NwsFApNJpNhwBj/n5SnHZ2DKMrKythsdldXF4lEksvlOjsolcry8vKSkpKSkhIWizVpn66urmaMBYpH87Q16u/vZ7FYZ8+ePXLkyLlz59LT0zGNFhsu0KimpubIGCQSyd43FqbRAma6GpWUlISFhcEOFRUVgSCIabQImZZGFArlxx9/PHLkyOnTpwsKCkQikT2HMI0WNtPSiEqlXrp0CdYoPz9fKBRiGi1OpntSKy0tRU5qZDJZIpFgGi1CXBCxa2trjx49ikXsxYwLNJLL5Ww2G/7BHxISQiQSMY0WGy7QSKfTKZXKioqK0tLS0tJSNpuNabTYcI1GzoBptIDBNMJwAZhGGC4A0wjDBcyeRjKZDMRYoDirUVZWVmNjYysGxmQ4pZFAICjCwLCPUxpN51yGsRjANMJwAZhGGC4A0wjDBTilkVarVS0OtFrtXI+IW+KURgqFgrc4UCgUcz0ibomzGvX09JhMphcLF5PJ1NPTg2k0NZzVSCAQjIyMQAuXkZERgUAgEonmekLYNchkMkyjOQDWSCwWz7UALkAoFIrFYvfTaNRi7VUPipTGSZtQYXwmNnaIbJtSa55NURwDazTxpKZSqWQymUwm652ARCKZ5t8ZZwipVOqWGmlN5n9ltp1Mapq0Hb3d9KezTX88aduSivscD63VarVYLDYLLRaL1Wp1gTjjsadRV1dXVVVVZWUllUqloCguLs56QGKzG2ZztJzEvTWKLFHEV5viq03x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sXGjNn8itkZYmxL14WtvvL5s6ZLdh1ytkaOIzWO1EYPW7LwWV/q0S9P65EHiiV+dS2vvbZ/rsXGjNn8i9uiwUSPvbmznplzcHvaTqzVyFLEVSqmIx2wRdvaq+zQCFoV4actfrzPEjX1zPzzu0uZbxH4BQRW3/S7HuVojZyN2bwOdEHPgf47imkCOYu6Hx13afIvYM6URCILfhoZV2YnYcBO10MmpF78LOvV5QDatRyGY67Fxo5ZNmi8RG2amNFIqVWVPGF0OZ7E7qbcignb9318PnMNXVz7TiORzPzzu0r4JDpknERtmpjRyehZb0lCScOWTXx0h8J50zf3wuEubPxEbZqY0cnoWW9tdX1xwcevu6BoqRzHnw+MuDYvYBpDfys796QS+soLbJ9f0t1Wm3/76f7+8zSlrfz7nw+MuDYvYBrC7jZVz9ctTp777EbgWffXf4SGnAk8llIEcydwPj7u0+RaxhyGo6WFYSnZqjdP32b2cl0bsXlBUFvPpwb2bNn6w6eMvTp65z+f3aed8bNyozbeIPSPAEdsHu1BkxppSNb8i9oyAXSgy022+RewZAbtQZKbbfIvYM4KTs9hYm3KbbxF7RnByFhtrU26LK2Kn38/uU2plKl2vXCNX66WK51jpknJuIrbBYBiYRQwGg1qtbmhoCDhw4FZsLIVK27pte3d3z/ETJ7HSJeWJkydnNWJTaGV6g2F4jigrK2tqahIKhTk5OTqdDitdWLa2ts6eRnNy8zXGvAXTCMMFYBphuABMIwwXgGmE4QIwjTBcAKYRhgvANMJwAZhGGC4A0wjDBfw/CiS8VFxcMUMAAAAASUVORK5CYII=" alt="" />

小结:

1)TRUNCATE太快了,清除10W数据一点没压力,批量删除次之,最后的DELTE太慢了

2)TRUNCATE快是因为它属于DDL语句,只会产生极少的日志,普通的DELETE不仅会产生日志,而且会锁记录

PS:

参考学习网址:http://www.cnblogs.com/panchunting/archive/2013/04/27/SQL_Tech_001.html

sql server中的大数据的批量操作(批量插入,批量删除)的更多相关文章

  1. .SQL Server中 image类型数据的比较

    原文:.SQL Server中 image类型数据的比较 在SQL Server中如果你对text.ntext或者image数据类型的数据进行比较.将会提示:不能比较或排序 text.ntext 和 ...

  2. 删除sql server中重复的数据

    原文:删除sql server中重复的数据 with list_numbers as( select Name, AuthorOrTime, Url, Price, EstimatePrice, Si ...

  3. sql Server中临时表与数据表的区别

    sql server 中临时表与数据表的区别 1.如何判断临时表和数据表已生成 --如何判断临时表是否已创建--- if exists(select * from tempdb..sysobjects ...

  4. 转:Sql Server中清空所有数据表中的记录

    如果要删除数据表中所有数据只要遍历一下数据库再删除就可以了,清除所有数据我们可以使用搜索出所有表名,构造为一条SQL语句进行清除了,这里我一一给各位同学介绍.   使用sql删除数据库中所有表是不难的 ...

  5. SQL Server中Table字典数据的查询SQL示例代码

    SQL Server中Table字典数据的查询SQL示例代码 前言 在数据库系统原理与设计(第3版)教科书中这样写道: 数据库包含4类数据: 1.用户数据 2.元数据 3.索引 4.应用元数据 其中, ...

  6. Sql Server中清空所有数据表中的记录

    Sql Server中清空所有数据表中的记录 清空所有数据表中的记录: 代码如下:exec sp_msforeachtable  @Command1 ='truncate table ?'删除所有数据 ...

  7. 通过DBCC Page查看在SQL Server中哪行数据被锁住了?

    原文:通过DBCC Page查看在SQL Server中哪行数据被锁住了? 如何查看被锁的是哪行数据?通过dbcc page可以. 要想明白这个问题: 首先,需要模拟阻塞问题,这里直接模拟了阻塞问题的 ...

  8. sql server中的分页数据查询

    1.引言 今天在工作中遇到一个需要进行sql server分页数据查询的问题,但是分页数据查询的sql却忘记了,最终通过查询资料解决了该问题.现在把解决方法记下,以备查阅. 在这里需要感谢博客园的Ql ...

  9. SQL Server中sp_spaceused统计数据使用的空间总量不正确的原因

    很多时候,我们经常使用sp_spaceused来查看表的空间使用情况,上个月群里有个网友说他使用DELETE删除了数据后,使用sp_spaceused查看,发现该表的分配的空间总量(reserved) ...

随机推荐

  1. inotify工具安装配置

    一.安装 1)  从内核和目录里面查看是否支持inotify [root@nfs01 ~]# uname -r 2.6.32-573.el6.x86_64 [root@nfs01 ~]# ls -l ...

  2. Python3基础 while 斐波那契数列

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. Python3基础 else 循环完整结束才执行

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. redhat7 防火墙设置

    查看防火墙的状态# firewall-cmd --staterunning # systemctl stop firewalld   //关闭防火墙服务# systemctl start firewa ...

  5. require的压缩命令

    注意点 node r.js -o baseUrl=js name=main out=js/build.js paths.jquery=empty: 注:baseUrl是可选的 取决于页面是否有写这个入 ...

  6. 【Coursera】Security Introduction -Summary

    对这门课程的安全部分进行一个小结. 往期随笔 第八周第一节 第八周第二节 第九周第一节 第九周第二节 前言:为什么互联网要提及安全 因为security牵扯到我们每一个人,有人每时每刻都想着要偷取别人 ...

  7. HDU 1171 Big Event in HDU(0-1背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:给出一系列的价值,需要平分,并且尽量接近. 思路:0—1背包问题. 0-1背包问题也就是有n种物品且 ...

  8. 微信小程序之可滚动视图 scroll-view 的使用注意

    微信小程序之可滚动视图 scroll-view 使用注意: 1.scroll-view 中的需要滑动的元素不可以用 float 浮动: 2.scroll-view 中的包裹需要滑动的元素的大盒子用 d ...

  9. perl usage()和getopt

    #!/usr/bin/perl#perl search.pl --infile Targets.Lung.Carcinoma.genelist.txt --homogene Homo_sapiens. ...

  10. Linux基础※※※※Linux中的图形相关工具

    kolourPaint类似于Win中个mspaint: Ubuntu安装:sudo apt-get install kolourpaint4 图1 kolourPaint界面 其他类似的画图工具见链接 ...