How to get the number of rows affected in an insert in MySQL

2

In SQLServer I use after insert or update I use:

SET @LINHAS_AFETADAS = @@ROWCOUNT

So I get the number of rows affected, I would like to know the equivalent in MySQL, I searched the web but found only code solutions, I need to do it directly in query , tried ROW_COUNT() , but this function returned 0 for no affected row and -1 for 1 or more row.

    
asked by anonymous 17.03.2015 / 17:04

1 answer

3

According to the official MySQL documentation , the SELECT ROW_COUNT() , is what works.

If you are testing in the MySQL Workbench, this may not seem to work, as this comment .

At documentation there is also this note :

  

Important

     

ROW_COUNT () is not replicated reliably using statement-based replication. Beginning with MySQL 5.1.23, this function is automatically replicated using row-based replication. (Bug # 30244)

    
17.03.2015 / 17:59