Find out if REPLACE statement has replaced or just inserted in MySQL

后端 未结 3 1561
粉色の甜心
粉色の甜心 2020-12-11 08:39

Is there a way in MySQL to find out if the last REPLACE statement actually replaced any row or just performed a regular insert? LAST_INSERT_ID() doesn\'t seem t

3条回答
  •  盖世英雄少女心
    2020-12-11 08:55

    You need to determine the affected rows count. REPLACE doesn't update rows; it inserts or deletes and then inserts.

    From the MySQL manual:

    The affected-rows count makes it easy to determine whether REPLACE only added a row or whether it also replaced any rows: Check whether the count is 1 (added) or greater (replaced).

    Check out the manual page: MySQL REPLACE Syntax

提交回复
热议问题