Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
Transaction doesn't rollback when one of the statements fail in MySQL

I've simple transaction here;

START TRANSACTION;
INSERT INTO user_photos(id, user_id, meta, upload_timestamp) VALUES (1211, 1, '{"a"}', 
from_unixtime(unix_timestamp()));
UPDATE user_photos set user_id = '{"test"}' WHERE user_id = 1;
COMMIT;

The INSERT statement will work but the second statement, the UPDATE statement, will fail as the user_id column has type of INTEGER.

I would like to have a transaction which will rollback if any statement(inside transaction) fails. This transaction doesn't behave like that.

I use INNODB engine. Why is this transaction not working?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

MYSQL has no "autorollback" features at transaction level.

If some statement has failed, this statement is rolled back but the transaction is not rolled back. If you run COMMIT, MySQL commits all non rolled back statements of the current transaction: that is what happened. if you run ROLLBACK, all statements are rolled back whether they failed or succeeded.

If you want a different behaviour you need to code it in your application code. This can be done with a stored procedure: see mysql transaction - roll back on any exception.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!