I used to count the number of affected rows using the @@ROWCOUNT
.
DECLARE @TotCount INT
DELETE * FROM TabA WHERE A = 'a'
SET @TotCount = @TotCount + @@ROWCOUNT
DELETE * FROM TabB WHERE B = 'b'
SET @TotCount = @TotCount + @@ROWCOUNT
UPDATE TabC SET C = 'c' WHERE C='d'
SET @TotCount = @TotCount + @@ROWCOUNT
But think of a situation, where the script has many DELETE
and UPDATE
statements. Is there a way to count the number of all affected rows at once?