Sobes.tech
Junior — Middle

Explain what is meant by a transaction in a database or information system.

sobes.tech AI

Answer from AI

A transaction in a database or information system is a sequence of operations executed as a single unit. The main properties of a transaction are described by the acronym ACID:

  • Atomicity — all operations of the transaction are completed fully or not at all.
  • Consistency — the transaction transforms the database from one correct state to another.
  • Isolation — parallel transactions do not affect each other.
  • Durability — after commit, changes are saved even in case of failures.

In C#, for working with transactions, the TransactionScope class is often used:

using (var scope = new TransactionScope())
{
    // database operations
    // if all successful
    scope.Complete();
}

If Complete() is not called, the transaction is rolled back, ensuring data integrity.