There is a sql like that
UPDATE xxx SET num = num -1 WHERE num > 0;
Will this be an atomic operation even if I have no transaction statement?
Can this sql ensure the num field always be non-negative?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If autocommit is enabled, yes it will be executed atomically. Every statement will be a single transaction unless autocommit is disabled.
It should be noted that autocommit is enabled by default, hence why START TRANSACTION is usually necessary to initiate a transaction.