create procedure sinckypro
as
declare @i int
set @i=1
begin transaction tran_sincky
create table sinckytab(
myid int not null,
myname varchar(10),
mtdesc varchar(50))
save tran save_sincky /*设置保存点*/
while @i<=101
begin
insert into sinckytab values(@i,'sincky','come from 51testing')
set @i=@i+1
end
select * from sinckytab
if @@rowcount!=100
begin
print '100行数据生成失败'
rollback tran tran_sincky /*回滚到事务开始, 当设置成rollback tran save_sincky 执行失败*/
end
else
begin
print '100行数据生成成功'
commit tran tran_sincky
end
exec sinckypro
有个问题:
我是设置101次循环,把事务回滚设置成事务开始rollback tran tran_sincky,执行语句,显示“100行数据生成失败”
当我把回滚语句设置成rollback tran save_sincky时候,执行失败
错误提示是:EXECUTE 后的事务计数指出缺少了 COMMIT 或 ROLLBACK TRANSACTION 语句。