This MySQL statement instructs the server to reverse SQL statements for the current transaction back to a point marked in the transaction by the SAVEPOINT statement.
hits past month: 11 ; last updated: may 4, 2009 - 2:34am ; parent: MySQL Transaction StatementsROLLBACK TO SAVEPOINT identifier
This MySQL statement instructs the MySQL server to reverse SQL statements for the current transaction back to a point marked in the transaction by the MySQL statement, SAVEPOINT. Any transactions for the session made after the savepoint are undone. This is in contrast to the MySQL statement, ROLLBACK by itself, which undoes all changes since the start of the transaction. Transaction statements are currently supported by the InnoDB, NDB Cluster, and BDB storage engines and are ignored if used with MyISAM tables. Multple savepoints may be set up during a transaction.
Below is an example of this MySQL statement:
START TRANSACTION; LOCK TABLES orders WRITE; INSERT DATA INFILE '/tmp/customer_info.sql' INTO TABLE orders; SAVEPOINT orders_import; INSERT DATA INFILE '/tmp/customer_orders.sql' INTO TABLE orders; SELECT... SAVEPOINT orders_import1; INSERT DATA INFILE '/tmp/customer_orders1.sql' INTO TABLE orders; SELECT... ROLLBACK TO SAVEPOINT orders_import1;
In this example, the database administrator has imported a customer information file and two files containing customer orders and has set up two savepoints. After running a few SELECT statements (not fully shown here), he decides that there was a problem loading the second batch of orders, so he rollsback the transaction to the savepoint, eliminating the data that was imported from the customer_orders1.sql file. If he wants, he can still rollback all of the orders imported, as well as the whole transaction. When he's finished, he can commit the transactions by executing the MySQL statement, COMMIT. See the description of that statement in our MySQL documentation for more information on committing transactions explicitly and implicitly.