Devolver el nº de registros afectados en una consulta update

14 views
Skip to first unread message

avazq...@gmail.com

unread,
Sep 1, 2025, 8:51:12 AM (7 days ago) Sep 1
to ado-h...@googlegroups.com

Buenas

Necesito saber el número de registros afectados por un update.

He probado con mysql_affected_rows y similares que he encontrado, pero siempre me da error.

Alguna idea?
Gracias

Saludos.

 

Antonio Vázquez

avazq...@gmail.com

 

David Field

unread,
Sep 4, 2025, 1:48:33 PM (4 days ago) Sep 4
to ADO Harbour
Hola Antonio,

SELECT ROW_COUNT() 
De acuerdo con preguntar en el navegador

In MySQL, the number of affected rows by the last INSERTUPDATE, or DELETE statement can be retrieved using the ROW_COUNT() function. This function returns the number of rows that were actually changed by the preceding statement. 
For example, to get the number of rows affected by an UPDATE statement:
Código
UPDATE your_table SET column_name = 'new_value' WHERE condition;SELECT ROW_COUNT();
Important Considerations:
  • ROW_COUNT() should be called immediately after the INSERTUPDATE, or DELETE statement to ensure it reflects the correct operation.
  • For UPDATE statements, ROW_COUNT() returns the number of rows where the new value is different from the old value. If a row's value is updated to the same value it already had, it is typically not counted as an "affected" row by default.
  • For REPLACE statements, ROW_COUNT() returns 2 if an old row was deleted and a new one inserted, or 1 if a new row was inserted without replacing an old one.
  • For INSERT ... ON DUPLICATE KEY UPDATE statements, ROW_COUNT() returns 1 for a new insertion, 2 for an update of an existing row, and 0 if an existing row is set to its current values (unless CLIENT_FOUND_ROWS is used, in which case it returns 1 for the latter case). 
  • ROW_COUNT() does not account for rows implicitly affected by cascading foreign key actions (e.g., ON DELETE CASCADE).
  • For SELECT statements, ROW_COUNT() behaves similarly to mysql_num_rows(), returning the number of rows retrieved.

Antonio Vázquez

unread,
Sep 4, 2025, 4:02:38 PM (4 days ago) Sep 4
to ado-h...@googlegroups.com
Gracias David.
Abrazo

Enviado desde Outlook para Android

From: ado-h...@googlegroups.com <ado-h...@googlegroups.com> on behalf of David Field <david...@gmail.com>
Sent: Thursday, September 4, 2025 7:48:33 PM
To: ADO Harbour <ado-h...@googlegroups.com>
Subject: [ADO Harbour] Re: Devolver el nº de registros afectados en una consulta update
 
--
Has recibido este mensaje porque estás suscrito al grupo "ADO Harbour" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a ado-harbour...@googlegroups.com.
Para ver este debate, visita https://groups.google.com/d/msgid/ado-harbour/136c3142-ba13-49df-bfcb-6e515aef41ffn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages