MyISAM does not support transactions, but how do I implement a rollback if I encounter a database error? for example:
A program must first insert a table, and then insert the B table. The following line is not logical:
aResut=doInsertAif(aResut){ bResult=doInsertB if (!bResult){ delete aResult from a } }
Reply content:
MyISAM does not support transactions, but how do I implement a rollback if I encounter a database error? for example:
A program must first insert a table, and then insert the B table. The following line is not logical:
aResut=doInsertAif(aResut){ bResult=doInsertB if (!bResult){ delete aResult from a } }
Change into InnoDB
Binlog
Hello, you're right MyISAM
. Rollback is not supported. However, there are several measures to prevent data loss in advance:
Either the storage engine is changed InnoDB
;
Either save the statement for each execution SQL
;
or a regular part.
Upstairs said binlog
I am also very curious what the ghost, my answer above narrow. So I found this thing: mysqlbinlog+myisam implementation of MySQL anytime, anywhere recovery method
MyISAM does not support transactions, change to InnoDB bar
and Binlog can recover data, but not real-time recovery.
Table with InnoDB Bar.
Then define an exception, such as that the table does not exist
Begin
DECLARE flag varchar (32);
--Defining exceptions
Declare exit handler for 1146
Begin
rollback ;...
End
Set autocommit = 0; --Open transaction
Aresut=doinserta
if (Aresut) {
Bresult=doinsertb
if (!bResult){ -- 触发异常回滚
}
--Submit
commit;
There is no way, MyISAM is not support business, change to InnoDB bar
If you do not need to use MyISAM, you can use this to insert the temporary table first, if the execution succeeds insert tableA from select id name from tableb
. This simulates things. Can be encapsulated as a stored procedure