Home > DeveloperSection > Forums > how to use commit or rollback statement in the the SQL
Elena Glibart
Elena Glibart

Total Post:35

Points:128
Posted on    September-30-2016 12:46 AM

 Database SQL Server 
Ratings:


 1 Reply(s)
 338  View(s)
Rate this:
Hi 
Please  tell me how to use commit or rollback statement in the the SQL
thanks


Abhishek Srivasatava
Abhishek Srivasatava

Total Post:24

Points:168
Posted on    September-30-2016 1:03 AM

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

 


Don't want to miss updates? Please click the below button!

Follow MindStick