我在我的存储过程中使用“Set RowCount”。我有一个问题,Set RowCount的范围是什么?考虑以下SP
CREATE PROC Test
AS
BEGIN
SET ROWCOUNT 10
...........
SET ROWCOUNT 0
END
CREATE PROC Test2
AS
BEGIN
...........
SET ROWCOUNT 0
END
CREATE PROC Test3
AS
BEGIN
SET ROWCOUNT 10
...........
END
CREATE PROC Test4
AS
BEGIN
SET ROWCOUNT 10
SET ROWCOUNT 5
...........
SET ROWCOUNT 0
END
现在在上面的SP中,你必须看到我有不匹配的SetRowcount语句。所以我的问题是,如果我忘记将“Set RowCount 0”添加到我的开头“Set RowCount N”语句中。有必要吗?它会影响我申请中其他SP的执行吗?
答案 0 :(得分:5)
与accepted answer in the question linked to in the comments相反,据我所知,此范围规则与#temp
表可见性的范围规则完全相同。它传播到子批次,但是当批次退出时,它会重置为之前的值。
CREATE PROC #bar
AS
SELECT * FROM sys.objects
EXEC ('SELECT * FROM sys.objects')
GO
CREATE PROC #foo
AS
SET ROWCOUNT 1
EXEC #bar
GO
SET ROWCOUNT 4
EXEC #foo /*Returns 2 resultsets with 1 row*/
EXEC #bar /*Returns 2 resultsets with 4 rows*/
DROP PROC #foo
DROP PROC #bar