MySQL Tutorial/Information Functions/ROW COUNT

Материал из SQL эксперт
Перейти к: навигация, поиск

ROW_COUNT() returns the number of rows updated, inserted, or deleted by the preceding statement.

   <source lang="sql">

mysql> mysql> mysql> CREATE TABLE t (id INT NOT NULL); Query OK, 0 rows affected (0.01 sec) mysql> mysql> INSERT INTO t VALUES(1),

   ->                     (2),
   ->                     (3);

Query OK, 3 rows affected (0.00 sec) Records: 3 Duplicates: 0 Warnings: 0 mysql> mysql> SELECT ROW_COUNT(); +-------------+ | ROW_COUNT() | +-------------+ | 3 | +-------------+ 1 row in set (0.00 sec) mysql> mysql> DELETE FROM t WHERE id IN(1,2); Query OK, 2 rows affected (0.00 sec) mysql> mysql> SELECT ROW_COUNT(); +-------------+ | ROW_COUNT() | +-------------+ | 2 | +-------------+ 1 row in set (0.02 sec) mysql> mysql> drop table t; Query OK, 0 rows affected (0.00 sec) mysql> mysql></source>