Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 15:03:20
|
We can use @@ROWCOUNT to determine if there are any rows in SELECT statement. How do we determine if there were any records updated?Thanks. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 15:12:30
|
You can still use @@ROWCOUNT, but with one caveat. @@ROWCOUNT would return the number of rows touched, rather than rows where some column or other was changed. So for example, in the following, if there were any rows in the table where id = 3, you would get a non-zero number for @@ROWCOUNT even though the data was not materially changed:UPDATE tbl SET id = 3 WHERE id = 3; |
|
|
rama108
Posting Yak Master
115 Posts |
Posted - 2013-03-06 : 15:49:16
|
Thanks James. What if i do not have a where clause in update statement?UPDATE TableAFROM TableA aJOIN TableB bon a.ID = b.IDThanks. |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-03-06 : 17:02:42
|
It would return exactly the same number as you would get if you were to replace the update with a select SELECT *FROM TableA aJOIN TableB bon a.ID = b.ID;SELECT @@rowcount; |
|
|
|
|
|