The ROLLBACK TO SAVEPOINT Statement : Savepoint « Transaction « SQL / MySQL






The ROLLBACK TO SAVEPOINT Statement

     
mysql>
mysql>
mysql> CREATE TABLE Books
    -> (
    ->     BookID SMALLINT NOT NULL PRIMARY KEY,
    ->     BookTitle VARCHAR(60) NOT NULL,
    ->     Copyright YEAR NOT NULL
    -> )
    -> ENGINE=INNODB;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Books VALUES (103, 'Opera', 1966);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Books VALUES (104, 'Sql Server', 1932);
Query OK, 1 row affected (0.00 sec)

mysql> SAVEPOINT sp1;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Books VALUES (105, 'C', 1996);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Books VALUES (106, 'Pascal', 1980);
Query OK, 1 row affected (0.00 sec)

mysql> ROLLBACK TO SAVEPOINT sp1;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO Books VALUES (107, 'Postcards', 1992);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Books VALUES (108, 'Oracle', 1993);
Query OK, 1 row affected (0.00 sec)

mysql> COMMIT;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop table Books;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
  








Related examples in the same category

1.Create a savepoint with a name.