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
Liked By
Write Answer
how to use commit or rollback statement in the the SQL
Join MindStick Community
You have need login or register for voting of answers or question.
Abhishek Srivasatava
30-Sep-2016Hi 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.
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.