How to get the affected line number in an Mysql Insert

Asked

Viewed 749 times

2

In Sqlserver I use after the insert or update i use:

SET @LINHAS_AFETADAS = @@ROWCOUNT

So I get the affected line number, I would like to know what the equivalent in Mysql, I searched the web but only found solutions in codes, need to be done directly in query, tried ROW_COUNT(), but this function returned 0 for no affected line and -1 for 1 or more lines.

1 answer

3


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

If you’re testing in Mysql Workbench, it may not seem to work, as per this comment.

In the documentation there is also this remark:

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)

  • Thanks Fernando, really I was testing in Mysql Workbench ,in the application ROW_COUNT() worked as expected.

  • 1

    @Andre, I’m glad I could help. I noticed you’re new here. So, if the answers have completely solved your doubts regarding the question, please mark the answer that helped you best as an answer, and can also give positive votes in the other answers that helped you. And if you still have doubts edit the question with the same, or comment on the answers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.