Today, I'd want to revisit one of the most typical interview questions and replies, which I see frequently referenced in subsequent interviews.

Transaction

A transaction is a collection of SQL statements that operate as a single unit. In layman's terms, a transaction is a unit in which a series of tasks is completed in order to finish the entire activity. To better appreciate this, consider a bank transaction.

SQL Server ACID Properties
SQL Server's ACID properties assure data integrity during a transaction. A transaction is a series of SQL (insert, update, and delete) statements that are handled as a single unit and are executed using the completed or Not principle. To be successful, a transaction must adhere to the ACID Properties. Atomicity, Consistency, Isolation, and Durability are abbreviated as ACID.

Atomicity
Every transaction adheres to atomicity. It indicates that if a transaction is initiated, it must be completed or rolled back. To illustrate, if a person transfers money from account "A" to account "B," the money should be credited to account B after the transaction is completed. If a failure occurs, the modification should be rolled back after debiting the money from account "A." In other words, each transaction will either succeed or fail.

Consistency
Consistency says that after the completion of a transaction, changes made during the transaction should be consistent. Let’s understand this fact by referring to the above example, if account “A” has been debited by 200 RS, then after the completion of the transaction, account “B” should be credited by 200 RS. It means changes should be consistent. In simple words, Consistency means a guarantee that a transaction never leaves your database in a half-finished state.

Isolation

Isolation states that every transaction should be isolated from each other. There should not be any interference between the two transactions. In simple words, Any other operation cannot affect my operation.

Durability
Durability means that once the transaction is completed, all the changes should be permanent. It means that in case of any system failure, changes should not be lost. In simple words, When the Transaction is complete, the changes are saved.Now we can understand this with the help of a Figure. This is very easy for us. This Figure is shown below.

FAQs
Q. What is the difference between the Local and the Distributed SQL Server transactions?
The Local transaction is an SQL Server transaction that processes data from the local database server

The Distributed transaction is an SQL Server transaction that processes data from more than one database server

Q. Some transactions may not complete their execution successfully. Explain these transactions.
These transactions are known as,

Aborted.

Whenever a transaction finishes its final statement, it ultimately enters into this state:

Partially committed.
Q. What is the SQL Server Transaction Log LSN?
Each Transaction log record that is written to the SQL Server transaction log file can be identified by its Log Sequence Number (LSN).