The @ @ROWCOUNT in SQL Server returns the number of rows affected by the previous statement, and the return value type is int integer. if the number of rows is greater than 2 billion, you need to use Rowcount_big.
The values of the @ @ROWCOUNT and @ @ERROR variables always change after a statement is executed, so we should first save them in local variables as a basis for judgment. They reflect the impact of the last statement immediately after them!
We can usually detect whether any rows have changed by using the UPDATE, INSERT statement, and @ @ROWCOUNT.
For example:
UPDATE dbo. EmployeeSET = EmpNoWHERE 1=2 IF @ @ROWCOUNT = 0 PRINT ' no data has been modified ' ; GO
The execution results are:
(0 rows affected)
No data has been modified
UPDATE dbo. EmployeeSET = EmpNoWHERE 1=1-- Modify to fully execute IF@ @ROWCOUNT=0 PRINT' No data was modified '; GO
The execution results are:
(1135 rows affected)
@ @ROWCOUNT in SQL Server