Jump to content

[SOLVED] Number of rows affected by UPDATE - in a stored procedure


miseleigh

Recommended Posts

The MySQL manual says that the update statement returns the number of affected rows.  We're trying to figure out how to use that feature, and it seems that few people use it or even think about using it.  The way we've been doing it in the past has been performing the update and then doing a select to get the count.  However, we're trying to reduce the size of our stored procedure (we need it faster!) and combining those into one statement would help.

 

Any tips on this one?  It's been hard to find anything online.  Basically, in the stored procedure, we want something like

SET v_count = 
     UPDATE Users 
          SET active=1 
          WHERE username=v_username);

instead of

UPDATE Users 
     SET active=1 
     WHERE username=v_username;
SELECT COUNT(username) 
     INTO v_count 
     FROM Users 
     WHERE active=1 AND username=v_username;

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.