SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Transaction rowcount


Transaction rowcount

Author
Message
sakthimadan
sakthimadan
SSC-Enthusiastic
SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)

Group: General Forum Members
Points: 145 Visits: 79
Yeah thanks...

Now i got it...

Thanks for your reply..!!!
Steve Cullen
Steve Cullen
Right there with Babe
Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)Right there with Babe (749 reputation)

Group: General Forum Members
Points: 749 Visits: 1226
Yep. @@rowcount is a cruel mistress. I avoid her like a rash. :-D

Converting oxygen into carbon dioxide, since 1955.


SQLRNNR
SQLRNNR
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32555 Visits: 18556
Nice question. Thanks.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw

EugeneMoulin
EugeneMoulin
SSChasing Mays
SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)

Group: General Forum Members
Points: 611 Visits: 29
Nice question, but, if we run the given script, don't we have an error on this line ?



select @@rowcount-- check this one out



EuG
sakthimadan
sakthimadan
SSC-Enthusiastic
SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)SSC-Enthusiastic (145 reputation)

Group: General Forum Members
Points: 145 Visits: 79
No.. i'm not getting any error..

are you??
Fozzie
Fozzie
SSC-Addicted
SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)

Group: General Forum Members
Points: 453 Visits: 1172
The only errors encounted would be if you didn't have the database and table already created as the script relies on them existing.

There's nothing wrong with SELECT @@ROWCOUNT -- a comment
EugeneMoulin
EugeneMoulin
SSChasing Mays
SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)SSChasing Mays (611 reputation)

Group: General Forum Members
Points: 611 Visits: 29
Ok, but i thought there was a missing blank between "rowcount" and "--"...

EuG
Fozzie
Fozzie
SSC-Addicted
SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)SSC-Addicted (453 reputation)

Group: General Forum Members
Points: 453 Visits: 1172
I may be getting confused with what you're saying..

But all of this works fine


select @@rowcount-- check this one out

select @@rowcount -- check this one out

select @@rowcount -- check this one out

select @@rowcount
-- check this one out



These would not work

select @@rowcount- - check this one out

select rowcount -- check this one out

select @@rowcount -
- check this one out

select @@rowcount -- check
this one out



We've a policy at work to use /* */ for comments where possible in case peeps run comments over a line... but it's also a pain in the backside if you want to comment out a block with these already in.

What I've found a bit weird is, if you run SELECT @@ROWCOUNT by itself in a completely fresh window then you get 1 returned... slightly odd behaviour? For example run the below script, I've used different commenting in case of line wrapping.


SELECT @@ROWCOUNT /* Will return 1, even though we've not previousiy run a statement */

SELECT 1 WHERE 2 = 1 /* Will an empty record set */

SELECT @@ROWCOUNT /* Will return 0 as expected as the previous statement returned no rows */

SELECT @@ROWCOUNT /* Will return 1 as the previous statement returned a row i.e of 0 */


Dennissinned
Dennissinned
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1082 Visits: 289
Nice question.
Oleg Netchaev
Oleg Netchaev
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1783 Visits: 1814
Fozzie (8/5/2010)
What I've found a bit weird is, if you run SELECT @@ROWCOUNT by itself in a completely fresh window then you get 1 returned... slightly odd behaviour?

I think that there was a QotD about this in the past and it generated a lot of posts due to this behaviour. It is actually by design, and it all depends on what happens when you open first window. For example, if you open SSMS, open new window then @@rowcount is 1, but if you after opening new window go after database list dropdown and pick your database then select @@rowcount returns 0 simply because clicking in the dropdown silently issued use [your_db_name]; prior to you running select @@rowcount. Whatever settings are silently ran by SSMS depends on things such as your user options, database options, SSMS version etc. The bottom line is that when you open SSMS and do see select @@rowcount returns 1 out of the bat then it simply means that the latest silently executed for you by SSMS script affected one record.

Oleg
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search