Scope of “Set rowcount” in SQL

后端 未结 1 1472
孤独总比滥情好
孤独总比滥情好 2021-01-05 22:01

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         


        
相关标签:
1条回答
  • 2021-01-05 23:06

    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
    
    0 讨论(0)
提交回复
热议问题