Definition – What is SQL Transaction?

  • SQL Transaction is a single unit of work applied on a database.
  • Its a sequence of operations perfomed on database in an logical order.
  • The SQL statements of an transaction will be either commited or rolled back.
  • Transaction comprises with two results, they are either Success or Failure.


SQL Transaction Properties

Typically transactions have four standard properties and they are abreviated as ‘ACID’

  • Atomicity
  • Consistency
  • Isolation
  • Durability

Atomicity :

Transactions are aborted at point of failure, by this way it ensure the operations of work units were completed successfully.

Consistency :

Upon a successsful commited transcation, it will ensure the database state is changed.

Isolation :

Transactions will operate independently and transparently.

Durability :

In case of system failure, it ensures the result of commited Transaction is persist.

Transaction Commands

Following are the commands used to control the transactions.

COMMIT :

This command will save the changes.

Syntax

COMMIT;


ROLLBACK :

This command will roll back(undo ro revert) the changes.

Syntax

ROLLBACK;


SAVEPOINT :

This command creates save points for the groups of transactions that has to be ROLLBACK.

Syntax

SAVEPOINT SAVEPOINT_NAME;


SET TRANSACTION :

Sets a name on a transaction.

Syntax

SET TRANSACTION [ READ ONLY | READ WRITE]; 


Read SQL Guide

Pin It on Pinterest

Share This