全局变量@@RowCount 和函数RowCount_Big()用于返回上一条语句影响的行数。如果行数大于 20 亿,则需要使用ROWCOUNT_BIG()。
1,ROWCOUNT_BIG():
Following a SELECT statement, this function returns the number of rows returned by the SELECT statement.
Following an INSERT, UPDATE, or DELETE statement, this function returns the number of rows affected by the data modification statement.
Following statements that do not return rows, such as an IF statement, this function returns 0.
2, set RowCount @Num
设置sql语句影响的行数,ROWCOUNT的设置是和Session有关的。一个Session将使用最近一次设置的ROWCOUNT,直到Session结束或修改了ROWCOUNT。
SET ROWCOUNT 0
取消ROWCOUNT限制。
3, sample codes
SET ROWCOUNT 0 -- return 10 records select * from dbo.test --return value is 10 select @@ROWCOUNT --return value is 1 select ROWCOUNT_BIG() --alternate solution declare @n int set @n=10
时间: 2025-01-06 21:30:30