我有两个问题请问大家:
1,如果在存储过程中不显示的使用事务(begin tran ....commit tran),那么存储过程中执行的insert和update操作是否会自动提交
2,我想在循环中增加事务,也即是每个循环一次事务,每个事务要保证成功都成功,失败都失败。
这应该如何操作
1,如果在存储过程中不显示的使用事务(begin tran ....commit tran),那么存储过程中执行的insert和update操作是否会自动提交
2,我想在循环中增加事务,也即是每个循环一次事务,每个事务要保证成功都成功,失败都失败。
这应该如何操作
while(...)
begin
begin tran ...
..........
..........
commmit tran
end
while(...)
begin..........
..........
endcommmit tran这样吧
2.
create proc p_test
as
begin
declare @i int
set @i=1
begin transaction
while @i<10
begin
insert into tb select 1
if @@error<>0
begin
rollback
return
end
end
commit
end
2.create proc p_test
as
begin
declare @i int
set @i=1
begin transaction
while @i<10
begin
insert into tb select 1
if @@error<>0
begin
rollback
return
end
end
commit
end
as
begin
declare @i int
set @i=1
while @i<10
begin
begin transaction
insert into tb select 1
if @@error<>0
begin
rollback
continue
end
commit
end
end