HOW TO USE COMMIT OR ROLLBACK STATEMENT IN THE THE SQL

Elena Glibart

Total Post:42

Points:296
Posted by  Elena Glibart
 601  View(s)
Ratings:
Rate this:
Hi 
Please  tell me how to use commit or rollback statement in the the SQL
thanks
  1. Abhishek Srivasatava

    Post:24

    Points:168
    Re: how to use commit or rollback statement in the the SQL

    Hi Elena Glibart,

     

    Below is the answer for your question: 


    SQL COMMIT Statement:

    It is mainly use while creating transaction for SQL query.

    Transaction is the set of statement to perform the task.

    COMMIT statement is used to save the changes performed by the transaction statement.

     

    BEGIN TRAN  TR1 --(Creating transaction)
     
    INSERT INTO EE_EMPL_CAT4 (PRSN_INTN_ID, [EMPL_STAT_CD],[NAME],REFERENCE_ID)
        VALUES (565545, 'ACTIVE', 'R Raturi',159978)
       
     COMMIT;
     
     GO

     

    SQL ROLLBACK Statement:

    Rollback is used if there is any sort of error occurs while performing any set of transaction.

    For example there are 3 table, data need to update in all three table. If this task need to be done by single transaction then by chance any table is not able to update because of any reason then rollback function undo all the changes.



    BEGIN TRAN  TR1
     
    INSERT INTO EE_EMPL_CAT4 (PRSN_INTN_ID, [EMPL_STAT_CD],[NAME],REFERENCE_ID)
        VALUES (56116545, 'ACTIVE', 'DAVID',159978)
       ROLLBACK ;
     GO

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!