How to check if update query was executed or not in MySQL?



  • I have an update query in MySQL and I want to return true or false based on whether my update query was executed or not. Is there any way we can find whether the update query is executed?

    UPDATE table SET table.name = "Anthony" WHERE table.id = 3;
    IF (queryUpdated) THEN
        SELECT 1 AS updated;
    ELSE
        SELECT 0 AS updated;
    END IF;
    


  • I suspect you want the https://dev.mysql.com/doc/refman/8.0/en/information-functions.html#function_row-count

    UPDATE table SET table.name = "Anthony" WHERE table.id = 3;
    SELECT CASE WHEN ROW_COUNT() > 0 THEN 1 ELSE 0 END AS updated;
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2