x

SQL – COMMIT & ROLLBACK

Prev     Next

  • SQL COMMIT and ROLLBACK are few of the commands used in Transaction SQL (T-SQL).
  • Transaction SQL is an extension to the SQL which is used especially by MS SQL server and Sybase RDBMS. T-SQL has many advance features like procedural programming, local variables and many data processing functions.
  • T-SQL handles sequences of operations on a database/tables. i.e. when you perform INSERT or UPDATE or CREATE or DELETE operations in a database/table, then it is referred as a SQL transaction.
  • During SQL transactions, we need to handle errors and need to maintain data integrity in database/table.
  • For example, assume that you need to update some records based on some selection. After updating, you need to delete some records from the updated table. If the database is down or server is down in-between at any stage, then it’s our/programmer’s responsibility to handle errors and to maintain data integrity. T-SQL is used for this purpose.
  • Transaction SQL can be handled manually as well as a script that will run automatically as a sequence of commands which may have bunch of many SQL statements.

SQL – COMMIT:

  • COMMIT is one of the transactional SQL command which is used to save changes.
  • For example, if you delete/update some records from a table, then this change will be existing only on the current session. If you close your session, then it may not be saved in the table/database. But, after delete/update transaction, if you save this operation by COMMIT command, then it will be permanently saved in table/database.
  • Syntax:
    COMMIT;

SQL – ROLLBACK:

  • ROLLBACK is one of the transactional SQL command which is used to rollback the changes.
  • For example, if you delete/update some records from a table, then this change will be existing only on the current session. If you close your session, then it may not be saved in the table/database. But, after delete/update transaction, if you save this operation by ROLLBACK command, then it will be permanently saved in table/database.
  • Syntax:
    ROLLBACK;

Prev     Next



Like it? Please Spread the word!