DS
select cast(cast(20200101 as nvarchar(8)) as date)
Size: a a a
DS
DS
DS
АА
АА
А
А
А
KT
exec sp_WhoIsActive @get_full_inner_text = 1 также с логированием каждую секунду (если каждый шаг курсора выполняется быстрее, то часть событий потеряется конечно)AK
exec sp_WhoIsActive @get_full_inner_text = 1 также с логированием каждую секунду (если каждый шаг курсора выполняется быстрее, то часть событий потеряется конечно)
create table _t(i int)
create table _t1(i int)
go
insert _t values (1),(2),(3)
go
begin tran
declare One cursor for
select i from _t
declare @t int
open One
fetch One into @t
while @@FETCH_STATUS = 0
begin
insert _t1(i) select @t
select * from _t1
fetch One into @t
end
close One
deallocate One
rollback tran2_
These actions should always be there. Always. You may argue that the line
IF @@trancount > 0 ROLLBACK TRANSACTION
is not needed if there no explicit transaction in the procedure, but nothing could be more wrong. Maybe you call a stored procedure which starts a transaction, but which is not able to roll it back because of the limitations of TRY-CATCH. Maybe you or someone else adds an explicit transaction to the procedure two years from now. Will you remember to add the line to roll back then? Don't count on it. I can also hear readers that object if the caller started the transaction we should not roll back.... Yes, we should, and if you want to know why you need to read Parts Two and Three. Always rolling back the transaction in the CATCH handler is a categorical imperative that knows of no exceptions.
KT
These actions should always be there. Always. You may argue that the line
IF @@trancount > 0 ROLLBACK TRANSACTION
is not needed if there no explicit transaction in the procedure, but nothing could be more wrong. Maybe you call a stored procedure which starts a transaction, but which is not able to roll it back because of the limitations of TRY-CATCH. Maybe you or someone else adds an explicit transaction to the procedure two years from now. Will you remember to add the line to roll back then? Don't count on it. I can also hear readers that object if the caller started the transaction we should not roll back.... Yes, we should, and if you want to know why you need to read Parts Two and Three. Always rolling back the transaction in the CATCH handler is a categorical imperative that knows of no exceptions.
YS
ВК
D
D
ПЛ
ПЛ
D
ПЛ