How to count the number of deleted rows in a MYSQL query?

I am trying to find out if the delete request is being executed correctly. I know how many lines should be deleted, and I would like to check that the number that was deleted matches the expected one from the request itself.

How to find out the number of rows I just deleted from an SQL query working with MySQL? Individual statements are great if I can chain them into a single query.

+7
source share
2 answers

this is the query you want, SELECT ROW_COUNT ()

mysql> DELETE FROM t WHERE i IN(1,2); Query OK, 2 rows affected (0.00 sec) mysql> SELECT ROW_COUNT() as DelRowCount; +-------------+ | DelRowCount | +-------------+ | 2 | +-------------+ 1 row in set (0.00 sec) 
0
source

Source: https://habr.com/ru/post/902329/


All Articles