If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to find out count of rows affected in a update statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-09, 14:18
Ravi_R Ravi_R is offline
Registered User
 
Join Date: Mar 2006
Posts: 16
How to find out count of rows affected in a update statement

Hi,

I am on db2 v8.2 udb/aix. Is there any way to find out the number of rows that were affected by running an update sql ? Do i need to create a update trigger to capture this ?

Thanks,
Ravi

Last edited by Ravi_R; 06-10-09 at 15:02.
Reply With Quote
  #2 (permalink)  
Old 06-10-09, 15:07
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
GET DIAGNOSTICS SQL-variable-name = ROW_COUNT

or

sqlerrd(3) in SQLCA
Reply With Quote
  #3 (permalink)  
Old 06-10-09, 16:28
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
If you are running the SQL in a script or from the command line, use the -a option:

db2 -a "update table-name set ........."

This will show the SQLCA and the number of rows affected in insert, update, or delete is in sqlerrd(3). Does not show rows selected.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 06-10-09, 17:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
select count(*) from final table (update ...)
Reply With Quote
  #5 (permalink)  
Old 06-11-09, 02:44
dr_te_z dr_te_z is offline
Registered User
 
Join Date: Jan 2009
Location: Zoetermeer, Holland
Posts: 555
b.t.w. as far as I know there is no way to determine the number of rows affected if a DELETE also throws rows away because of a "DELETE CASCADE" rule. Am I correct?
Reply With Quote
  #6 (permalink)  
Old 06-11-09, 09:31
Ravi_R Ravi_R is offline
Registered User
 
Join Date: Mar 2006
Posts: 16
Tks for the suggestions - it works fine for what i am trying to do here .
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On