Reliability @@ROWCOUNT shows how many rows matched the WHERE in UPDATE , as opposed to how many of them actually changed?
The documentation for @@ROWCOUNT says:
Data Manipulation Language (DML) statements set @@ROWCOUNT to the number of rows affected and return this value to the client.
(My emphasis.)
But if I
CREATE TABLE [Foo] ([a] INT, [b] INT) GO INSERT INTO [Foo] ([a], [b]) VALUES (1, 1),(1, 2),(1, 3),(2, 2) GO UPDATE [Foo] SET [b] = 1 WHERE [a] = 1 SELECT @@ROWCOUNT GO
... I see 3 (the number of lines matching [a] = 1 ), and not 2 (the number of lines changed by UPDATE - one of the three lines already had a value of 1 for b ). This seems like a strange definition of “affected” (not so, it just contradicts the way I usually use the word - in fact it is very convenient for what I want to do).
(A similar MySQL ROW_COUNT function, for example, would return 2 in this situation.)
Is this a robust behavior, ideally documented somewhere that I just didn't find? Or there are cases with odd edges ...
To be clear: I am not asking if 3 correct. I ask if this answers a reliable answer, or if there are extreme cases where SQL Server leaves rows that match but don't require changes.
Update . Several people asked (or hinted) what problems with "reliability" I worry. The fact is that they are quite foggy, but, it is no coincidence, replication? Deals? Markup? Indexes that he can use to avoid searching for strings, since he knows that b already 1 , and so he skips them? ...
Update . I was hoping someone with a more “insider” view of how SQL Server works to answer this question, but it looks like an example of the triggers (and others that I played with) from xacinay as close as we are going to receive. And that seems pretty damn. if he behaves in this way in the normal case, and he did not behave this way, despite the separation or whatsit, as someone said, surely this would qualify as a mistake. It is simply empirical, not academic.