๐Ÿ“ Understanding Transactions, Deadlocks & Log-Based Recovery in SQL ๐Ÿ’พ
dev.toยท1dยท
Discuss: DEV
Flag this post

๐Ÿ‘‹ Introduction

Have you ever wondered what happens when two people try to withdraw money from the same bank account at the same time? Databases handle such cases using transactions, locks, and recovery logs to make sure data always stays consistent.

In this blog, weโ€™ll explore:

  • How transactions maintain atomicity
  • What a deadlock is and how itโ€™s detected
  • How log-based recovery ensures data safety after a crash
CREATE TABLE Accounts (
acc_no INT PRIMARY KEY,
name VARCHAR(50),
balance INT
);

INSERT INTO Accounts VALUES
(1, 'Alice', 1000),
(2, 'Bob', 1500),
(3, 'Charlie', 2000);


โš™๏ธ 2๏ธโƒฃ Transaction โ€“ Atomicity & Rollback

๐Ÿง  Concept: A transaction ensures that all steps succeed or none at all. If any step fails, the database will rollback to thโ€ฆ

Similar Posts

Loading similar posts...