@@ROWCOUNT (TSQL Function)
Returns the number of records affected by the last statement.
Syntax
@@ROWCOUNT
Return Types
Returns bigint
.
Remarks
Some statements like USE
, BEGIN TRANSACTION
, COMMIT TRANSACTION
, ROLLBACK
reset the value of rowcount to 0.
With RSQL, the statement
SET @variable = value
doesn’t change the value of rowcount.
But with MS SQL Server, this statement sets the value of rowcount to 1.
Examples
CREATE TABLE t(a int IDENTITY NOT NULL, b int);
GO
DECLARE @a INT;
INSERT INTO t(b) VALUES (100), (101), (102);
PRINT @@ROWCOUNT; -- prints 3
SET @a = 10;
PRINT @@ROWCOUNT; -- prints 3 (MS SQL Server would print 1)
SELECT * FROM t WHERE b>100;
PRINT @@ROWCOUNT; -- prints 2
The result is:
3
3
a |b |
-----------+-----------+
2| 101|
3| 102|
(2 row(s) affected)
2