I'm trying to find out whether a delete query executed properly. I know how many rows its supposed to delete, and I'd like to check that the number that were deleted, matches what's expected, from within the query itself.
How do I find out the number of rows that I just deleted, from within a SQL query running against MySQL? Separate statements are fine, as long as I can bundle them into one query.
请参阅此处的MySQL ROW_COUNT函数http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_row-count
this is the query what 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.