USE tempdb
GO
--测试的存储过程
CREATE PROC p_test
AS
DECLARE tb CURSOR
FOR
SELECT 1
IF @@NESTLEVEL<2 EXEC p_test
DEALLOCATE tb
GO
--设置 CURSOR_DEFAULT 为 GLOBAL
ALTER DATABASE tempdb SET CURSOR_DEFAULT GLOBAL
PRINT 'CURSOR_DEFAULT GLOBAL'
EXEC p_test
--设置 CURSOR_DEFAULT 为 LOCAL
ALTER DATABASE tempdb SET CURSOR_DEFAULT LOCAL
PRINT 'CURSOR_DEFAULT LOCAL'
EXEC p_test
GO
--删除测试的存储过程
DROP PROC p_test
GO
--测试的存储过程
CREATE PROC p_test
AS
DECLARE tb CURSOR
FOR
SELECT 1
IF @@NESTLEVEL<2 EXEC p_test
DEALLOCATE tb
GO
--设置 CURSOR_DEFAULT 为 GLOBAL
ALTER DATABASE tempdb SET CURSOR_DEFAULT GLOBAL
PRINT 'CURSOR_DEFAULT GLOBAL'
EXEC p_test
--设置 CURSOR_DEFAULT 为 LOCAL
ALTER DATABASE tempdb SET CURSOR_DEFAULT LOCAL
PRINT 'CURSOR_DEFAULT LOCAL'
EXEC p_test
GO
--删除测试的存储过程
DROP PROC p_test