首页 新闻 会员 周边

SQL Server 中事务的回滚是否也回滚游标已经更改的数据?

0
悬赏园豆:30 [待解决问题]

事务开始

  --其他更改的sql语句

 

  游标

    游标更改数据

  游标

  

  --其他更改的sql语句

 

if 回滚或提交

 

平~安~喜~乐的主页 平~安~喜~乐 | 初学一级 | 园豆:86
提问于:2015-12-02 10:00
< >
分享
所有回答(2)
0

  是的,不过,哥们,这种情况,一试便知

悦光阴 | 园豆:2251 (老鸟四级) | 2015-12-02 10:01

试了别的数据库,在Mariadb中这种情况不会发生。游标已经更改的数据,事务回滚也不行。所以Sql Server 懒得试了。来问问。嘿嘿。

支持(0) 反对(0) 平~安~喜~乐 | 园豆:86 (初学一级) | 2015-12-02 10:03

@kangyangyang: 看你的用词,原来你是妹子

支持(0) 反对(0) 悦光阴 | 园豆:2251 (老鸟四级) | 2015-12-02 18:30

@悦光阴: I am a Man!!!

支持(0) 反对(0) 平~安~喜~乐 | 园豆:86 (初学一级) | 2015-12-03 14:58
0

会回滚~

 

给你的测试代码

----实验事务中有游标,存储过程的测试 
 
create table table_1 (a int)
insert into table_1
select 1
union all
select 2 
 
 
CREATE PROCEDURE [dbo].[test_insert] 
 
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
 
    -- Insert statements for procedure here
    insert into test (a) values(1000);
END
 
GO
 
 
create table test (a int )
 
begin tran 
insert into test (a) values (10);
insert into test (a) values (20);
 
declare cor cursor  for select a from table_1
declare @a int 
open cor
fetch next from cor into @a
while (@@fetch_status=0) 
begin
insert into test (a) values (@a)
fetch next from cor into @a
end 
close cor
deallocate cor 
 
exec test_insert
 
insert into test (a) values (100);
insert into test (a) values (200);
rollback 
 
select * from test 
--delete from test
Double_K | 园豆:173 (初学一级) | 2015-12-02 18:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册