Transactions
Introduction To Transactions In SQL
Introduction:
In this article, you will learn what transactions in SQL are.
The SQL Transaction is a collection of data. If we are doing any work in SQL, this is called a Transaction. It works into a single running unit. Every Transaction in SQL starts for performing a particular task. If our any task is not complete then, it gives an error “Transaction is not complete”. It is used to handle the transactions to provide the data integrity and to solve the database errors.
The Transaction has only two results: Win or Fail.
Properties of Transactions:
SQL transaction properties consist of mainly four types- Atomicity, Consistency Isolation and Durability. The property (ACID) is used to check the database and the Application architecture. If we want to a safe database, we should use ACID properties of the transactions.
Now, we will explain the work of the transactions properties:
- Atomicity: In this property of the transaction, whenever all work is not completed successfully, it returns the starting stage. It means our statement shows the error in the mid of the operation and it stops the working. This is known as a rollback.
- Consistency: In this property of the transaction, when any operation anstarted, it is called Consistency. If we create any transaction in the database and it runs successfully, our system automatically saves all the changes. It is also possible that our transaction gives an error before the completion. Rollback takes place automatically. This will return the system to its state before the transaction was started.
- Isolation: It is possible that in SQL, two transactions are same and execute at the same time. Each transaction is used for the limited time. SQL transaction protects, the system remains consistent, after the end of the transaction. When a transaction is not executing in the isolation, it will receive the data from the system, which is not consistent.
- Durability: We know that all the changes in our system are permanent. Any operation or transaction is durable, if it completed properly. This property allows the users to identify the complete transaction. Durability transaction is a fixed part of the system.
Transaction Control:
We will use these commands to control the transaction. These commands are used with the Insert, Update and Delete in SQL.
- Commit: This is used to save all the data or changes in the database.
- Rollback: This is used to save the data before last end commit.
- Savepoint: This is used to make a group of operations, in which to Rollback.
- Set Transaction: This is used to set the name on a transaction.
Summary:
Thus, we learnt, that the collection of the data and any activity in SQL is called Transaction.