MySQL INSERT IF (custom if statements)

前端 未结 5 1452
后悔当初
后悔当初 2020-11-27 04:37

First, here\'s the concise summary of the question:

Is it possible to run an INSERT statement conditionally? Something akin to this:

IF(         


        
5条回答
  •  余生分开走
    2020-11-27 05:03

    You're probably solving the problem the wrong way.

    If you're afraid two read-operations will occur at the same time and thus one will work with stale data, the solution is to use locks or transactions.

    Have the query do this:

    • lock table for read
    • read table
    • update table
    • release lock

提交回复
热议问题