Mysql Delete and Database Relationships
There is a more general question here:
- If I execute an SQL statement that touches multiple rows and it encounters an error after changing some rows, that's what happens.
The answer is essentially "none of them are affected, not even those that have already succeeded."
What's going on inside is pretty complicated. InnoDB supports transactional savepoints, and the database creates an implicit savepoint at the beginning of a statement in the current transaction. If the assertion fails partially, it rolls back to the implicit savepoint. This means it then looks like there never was such a statement (except when people insist on using the READ_UNCOMMITTED isolation level, which they shouldn't do if they're interested).
This happens regardless of whether you are using explicit transactions or not. If you are using explicit transactions, the current transaction is not rolled back (except for certain types of errors, such as deadlocks and a wait lock timeout where necessary so that a deadlock can be blocked), it only rolls back the beginning of the assertion instead.
a source to share