12. Transactions

Transactions in SQL

A transaction is a group of one or more SQL statements that are logically related and executed as a single unit of work. Transactions ensure the consistency and reliability of data, even in the presence of concurrent operations or unexpected system failures.

ACID Properties

Transactions in relational databases typically adhere to the ACID properties:

Atomicity

Consistency

Isolation

Durability

Example: Bank Transfer

Consider transferring 100 from Account X to Account Y:

  1. Debit X by 100 (X=X100)(X = X - 100).
  1. Credit Y by 100 (Y=Y+100)(Y = Y + 100).

Who Ensures the ACID Properties?

Backup and Restore

Databases typically offer backup and restore capabilities to protect data. Regular backups can be used to restore the database to a known consistent state if corruption or data loss occurs.

Security

Securing the database involves controlling user permissions, encrypting sensitive data, and safeguarding against unauthorized access. Proper security measures ensure that transactions are valid and conducted by authorized entities only.

Reference

The content in this document is based on the original notes provided in Azerbaijani. For further details, you can refer to the original document using the following link:

Original Note - Azerbaijani Version