use test
if object_id('tw') is not null drop table tw
create table tw(i int)
--第一种方法 日志多,运行快
dbcc sqlperf(logspace)
declare @i int
set @i=1
begin transaction
while @i<=10000
begin
insert into tw(i) values(@i/256)
select @i=@i+1
end
commit
dbcc sqlperf(logspace)
--第二种方法 日志少,运行慢
dbcc sqlperf(logspace)
select top 10000 a.id into #ta from sys.sysobjects a join sys.sysobjects b on 1=1
begin transaction
insert into tw(i)
select * from #ta
commit
drop table #ta
dbcc sqlperf(logspace)
--数据比较
--1、行集添加数据日志变化
TEST 109.7422 4.011978
TEST 109.7422 4.864028
--2、增加集合化添加数据日志变化
TEST 109.7422 4.864028
TEST 109.7422 5.192835
--结果分析
select 4.864028-4.011978,5.192835-4.864028
--------------------------------------- ---------------------------------------
0.852050 0.328807
附加说明:
但是要注意一点,在日志中包含太多的数据操纵查询,事务的持续时间将加长
在这时候,所有试图访问事务中引用的资源的其他查询将被阻塞