use tempdbgoset nocount on;set xact_abort on;goif OBJECT_ID('tempdb..tmp_zs_456') is not null drop table tmp_zs_456gocreate table tmp_zs_456 (id int primary key identity(1,1), szam int default 0)godeclare @id int = 0, @from_id int, @to_id int = 10000, @end_time datetime, @start_time datetimewhile @id < 1000000 begin set @id += 1 if @@TRANCOUNT = 0 begin tran insert into tmp_zs_456 default values if @id % 5000 = 0 AND @@TRANCOUNT <> 0 commitendif @@TRANCOUNT <> 0 commit-- Loop 1: the execution time is ok.select @start_time = GETDATE(), @from_id = 0while @from_id < @to_id begin select top 1 @from_id += 1 from tmp_zs_456 --select top 1 @from_id += 1 from sys.databasesendset @end_time = GETDATE()select DATEDIFF(millisecond, @start_time, @end_time) as execution_time_without_nolock-- Loop 2: the execution time is bigger. Why?select @start_time = GETDATE(), @from_id = 0while @from_id < @to_id begin select top 1 @from_id += 1 from tmp_zs_456 with (nolock) -- Here is the execution time is bigger. --select top 1 @from_id += 1 from sys.databases with (nolock) -- This is ok.endset @end_time = GETDATE()select DATEDIFF(millisecond, @start_time, @end_time) as execution_time_with_nolock