I am using "Set RowCount" in my Stored Procedures. I have one question, what is the scope of Set RowCount ? Consider the below SPs
CREATE PROC Test
AS
BEGIN
SET ROWCOUNT 10
开发者_Go百科 ...........
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
Now in the above SPs, you must be seeing I have mismatched SetRowcount statements. So my question what if I forgot to add "Set RowCount 0" to my opening "Set RowCount N" statement. Is it neccessary ? Will it affect the executions of rest of the SPs in my application ?
Contrary to the accepted answer in the question linked to in the comments as far as I can see the scope rules for this are exactly the same as those for #temp
table visibility. It propagates to child batches but when the batch exits it gets reset to the previous value.
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
精彩评论