Is a single sql expression always atomic in innodb?

There is such sql

UPDATE xxx SET num = num -1 WHERE num> 0;

Would it be an atomic operation even if I don't have a transaction statement?

Can this sql guarantee that the num field will always be non-negative?


source to share

1 answer

If autocommit is enabled, yes, it will execute atomically. Each operator will be a single transaction unless auto-protection is disabled.

It should be noted that autocommit is on by default, so a START TRANSACTION is usually required to start a transaction.



All Articles