MySQL: Transactions vs Locking Tables

后端 未结 6 1044
孤城傲影
孤城傲影 2020-11-28 00:36

I\'m a bit confused with transactions vs locking tables to ensure database integrity and make sure a SELECT and UPDATE remain in sync and no other connection interferes with

6条回答
  •  日久生厌
    2020-11-28 01:17

    I had a similar problem when attempting a IF NOT EXISTS ... and then performing an INSERT which caused a race condition when multiple threads were updating the same table.

    I found the solution to the problem here: How to write INSERT IF NOT EXISTS queries in standard SQL

    I realise this does not directly answer your question but the same principle of performing an check and insert as a single statement is very useful; you should be able to modify it to perform your update.

提交回复
热议问题