Database Reference
In-Depth Information
Tip
The More Savepoints the Better You can have as many savepoints as you want within
your MariaDB SQL code, and the more the better. Why? Because the more savepoints
you have the more flexibility you have in managing rollbacks exactly as you need them.
Note
Releasing Savepoints Savepoints are automatically released after a transaction
completes (a ROLLBACK or COMMIT is issued). Savepoints can also be explicitly
released using RELEASE SAVEPOINT .
Changing the Default Commit Behavior
As already explained, the default MariaDB behavior is to automatically com-
mit any and all changes. In other words, anytime you execute a MariaDB SQL
statement, that statement is actually being performed against the tables, and the
changes made occur immediately. To instruct MariaDB to not automatically
commit changes, you need to use the following statement:
Input
SET autocommit=0;
Analysis
The autocommit flag determines whether changes are committed automati-
cally without requiring a manual COMMIT statement. Setting autocommit to 0
(false) instructs MariaDB to not automatically commit changes (until the flag is
set back to true).
Note
Flag Is Connection Specific The autocommit flag is per connection, not serverwide.
Summary
In this chapter, you learned that transactions are blocks of SQL statements
that must be executed as a batch. You learned how to use the COMMIT and
ROLLBACK statements to explicitly manage when data is written and when it is
undone. You also learned how to use savepoints to provide a greater level of
control over rollback operations.
 
 
 
Search WWH ::




Custom Search