I wrote a bunch of delete statements and wrapped them in a transaction:
start transaction;
delete a...
delete b...
delete c...
rollback;
The idea is I would want the deletes to occur inside a transaction which would rollback upon completion. If a step failed along the way, I would want the successful steps to be rolled back as well.
To my chagrin delete a
worked, removing a few thousand rows, delete b
failed, but when I reran the statements all the records from a appeared to be gone.
Is this because the transaction is still open? I tried doing:
set session transaction isolation level read committed;
select a.*
and got back zero rows so I think that is not the case. Was the successful a
delete committed? And if so, how do I prevent that from happening until I can guarantee a full working query?
MySQL Workbench enables auto commit by default. In the SQL editor there is a toolbar button that can be used to toggle auto commit at will:
Somebody turned me on to, what I think, is a better way to do this:
begin;
<sql transactions>
commit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With