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
附加说明:但是要注意一点,在日志中包含太多的数据操纵查询,事务的持续时间将加长
在这时候,所有试图访问事务中引用的资源的其他查询将被阻塞
行添加和集合化添加数据后台的数据日志变化
最新推荐文章于 2024-09-27 11:23:13 发布
本文通过两种不同的SQL插入方法对比了日志记录的变化,并分析了不同方法下日志大小及事务执行效率的区别。实验显示,虽然逐行插入的方式运行更快,但产生的日志更多;而集合插入方式虽慢,但日志更少。
1万+

被折叠的 条评论
为什么被折叠?



