Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Rolling Back A Transaction in MySql

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 995
    Comment on it

    Transactions are very important part of MySql and for handling the transactions the Transaction Control Language (TCL) is used. Transactions are basically used to handle all the changes made in the database. Rolling back a transaction means storing the database to the last commited state. The Rollback statement can be understood with the help of other statements. The following commands should be understood for rollback of the transaction:-

    • COMMIT- This command is used to permanently save the transaction made in the database.
    • SAVEPOINT- This command is used to mark a point where whenever you want you can rollback to that point.
    • ROLLBACK-This command is used for rolling back or restoring the transaction to any savepoint in the database.

    Example for rollback of transaction-
    Suppose there is a table by name Customers

    PId                  NAME                     COUNTRY
     1                   John                    Australia
     2                  Robert                    England
     3                 Chi-zung                    China
    

    INSERT into CUSTOMERS values(4,'alex','Germany');
    commit;
    UPDATE CUSTOMERS set name='Julia' where PId='4';
    savepoint A;

    Now the table will look like:-

       PId                  NAME                     COUNTRY
         1                  John                    Australia
         2                 Robert                    England
         3                 Chi-zung                  China
         4                 Julia                     Germany
    

    Now if we have to rollback the transaction to the SAVEPOINT A , the command should be-

    rollback to A;
    SELECT * from CUSTOMERS;

     PId                  NAME                     COUNTRY
       1                  John                    Australia
       2                 Robert                    England
       3                 Chi-zung                  China
       4                 Julia                     Germany
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: