SET CURSOR_CLOSE_ON_COMMIT ON --设置为ON时,下面的代码报错
--SET CURSOR_CLOSE_ON_COMMIT OFF --设置为OFF(默认值时),下面的代码正常
DECLARE tb CURSOR LOCAL
FOR
SELECT id=1 UNION ALL SELECT id=1
OPEN tb
DECLARE @id int
FETCH tb INTO @id
WHILE @@FETCH_STATUS=0
BEGIN
BEGIN TRAN
IF @id%2=1
COMMIT TRAN
ELSE
ROLLBACK TRAN
FETCH tb INTO @id
END
CLOSE tb
DEALLOCATE tb