MyISAM does not support transactions, but how can I roll back a database error? For example, a program needs to insert Table a before table B. The logic is as follows: {code...} MyISAM does not support transactions, but how can I implement rollback if a database error occurs? For example:
A program needs to insert Table a before inserting table B. The logic is as follows:
aResut=doInsertAif(aResut){ bResult=doInsertB if (!bResult){ delete aResult from a } }
Reply content:
MyISAM does not support transactions, but how can I roll back a database error? For example:
A program needs to insert Table a before inserting table B. The logic is as follows:
aResut=doInsertAif(aResut){ bResult=doInsertB if (!bResult){ delete aResult from a } }
Change to innodb
Binlog
Hi, you're right.MyISAMRollback is not supported. However, there are several measures to prevent data loss in advance:
Either change the storage engineInnoDB;
EitherSQLStatement to save;
Or regular backup
Said upstairs.binlogI'm also curious about what it is. My answer is too narrow. So I found this: mysqlbinlog + MyISAM Implementation of mysql restoration anytime, anywhere
Myisam does not support transactions. Change it to innodb.
In addition, binlog can recover data, but cannot be recovered in real time.
Use innodb for tables.
Define an exception. For example, the table does not exist.
Begin
Declare flag varchar (32 );
-- Definition exception
Declare exit handler for 1146
Begin
rollback ;...
End
Set autocommit = 0; -- start the transaction
AResut = doInsertA
If (aResut ){
BResult = doInsertB
If (! BResult) {-- trigger an exception rollback insert into abcdefghijklmn (a) values ('A ');}
}
-- Submit
Commit;
No way. myisam does not support transactions. Replace it with innodb.
If you do not need to use myisam, you can use this method to insert a temporary table first. If the execution is successful, useinsert tableA from select id name from tablebSimulate things in this way. Can be encapsulated as a stored procedure