Do database transactions prevent race conditions?

前端 未结 4 1905
失恋的感觉
失恋的感觉 2020-11-28 04:52

It\'s not entirely clear to me what transactions in database systems do. I know they can be used to rollback a list of updates completely (e.g. deduct money on one account a

4条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 05:06

    It depends on isolation level (in serializable it will prevent race condition, since generally in serializable isolation level transactions are processed in sequence, not in paralell (or at least exclusive locking is used, so transactions, that modify the same rows, are performed in sequence). In order to prevent the race condition, better manually lock the record (mysql for example supports 'select ... for update' statement, which aquires write-lock on the selected records)

提交回复
热议问题