Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityThe Blood of Dawnwalker Director Says 60 FPS Is Enough for This RPG(23.09.2026 um 14:37 Uhr)
Windows Tipps & SecurityMeyer Sound ernennt John McMahon zum Chief Operating Officer(23.09.2026 um 11:19 Uhr)
Windows Tipps & SecurityTouchscreen erweitert Grill-Sortiment am Point of Sale(23.09.2026 um 13:45 Uhr)
Windows Tipps & Security„When Worlds Unite“: ISE 2027 erweitert Messe und Programm(23.09.2026 um 13:45 Uhr)
Sichere ProgrammierungWhat Full-Stack AI Engineering Means in Real Projects(23.09.2026 um 14:00 Uhr)
Sichere ProgrammierungThe Internet Changes Everything (Slowly)(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungMAUI vs React Native vs Flutter vs Ionic(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungAI Tools Used in Modern Software Development(23.09.2026 um 14:22 Uhr)
Sichere ProgrammierungHealthAuditor — Website Health & SEO Audit Tool(23.09.2026 um 14:24 Uhr)
Windows Tipps & SecurityThe Blood of Dawnwalker Director Says 60 FPS Is Enough for This RPG(23.09.2026 um 14:37 Uhr)
Windows Tipps & SecurityMeyer Sound ernennt John McMahon zum Chief Operating Officer(23.09.2026 um 11:19 Uhr)
Windows Tipps & SecurityTouchscreen erweitert Grill-Sortiment am Point of Sale(23.09.2026 um 13:45 Uhr)
Windows Tipps & Security„When Worlds Unite“: ISE 2027 erweitert Messe und Programm(23.09.2026 um 13:45 Uhr)
Sichere ProgrammierungWhat Full-Stack AI Engineering Means in Real Projects(23.09.2026 um 14:00 Uhr)
Sichere ProgrammierungThe Internet Changes Everything (Slowly)(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungMAUI vs React Native vs Flutter vs Ionic(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungAI Tools Used in Modern Software Development(23.09.2026 um 14:22 Uhr)
Sichere ProgrammierungHealthAuditor — Website Health & SEO Audit Tool(23.09.2026 um 14:24 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Database System Internals — Transactions, Deadlocks, Recovery & Indexing Explained with SQL Examples

Database System Internals — Transactions, Deadlocks, Recovery & Indexing Explained with SQL Examples Step 1: Create Table and Insert Sample Data CREATE TABLE Accounts ( acc_no INT PRIMARY KEY, name VARCHAR(50), balance INT ); INSERT I…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

Database System Internals — Transactions, Deadlocks, Recovery & Indexing Explained with SQL Examples

Step 1: Create Table and Insert Sample Data

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);



📸 Screenshot: Accounts table with 3 rows.



✅ Current State:



acc_no name balance

1 Alice 1000

2 Bob 1500

3 Charlie 2000

⚡ Task 1️⃣: Transaction – Atomicity & Rollback



Goal: Transfer ₹500 from Alice → Bob, then rollback before committing.



🧩 Step 1: Start Transaction

BEGIN TRANSACTION;



UPDATE Accounts SET balance = balance - 500 WHERE name = 'Alice';

UPDATE Accounts SET balance = balance + 500 WHERE name = 'Bob';



📸 Screenshot: Transaction started and updates pending.



🧩 Step 2: Rollback

ROLLBACK;



Now verify balances:



SELECT * FROM Accounts;



✅ Expected Output (No Changes):



acc_no name balance

1 Alice 1000

2 Bob 1500

3 Charlie 2000



📘 Explanation:

Atomicity ensures either all operations happen or none do.

Rollback prevented a partial transfer.



📸 Screenshot: Balances unchanged after rollback.



⚔️ Task 2️⃣: Deadlock Simulation



Goal: Create a deadlock scenario using two sessions.



🪄 Session 1:

BEGIN TRANSACTION;

UPDATE Accounts SET balance = balance - 100 WHERE name = 'Alice';

-- Lock held on Alice

UPDATE Accounts SET balance = balance + 100 WHERE name = 'Bob'; -- Will wait



🪄 Session 2:

BEGIN TRANSACTION;

UPDATE Accounts SET balance = balance - 200 WHERE name = 'Bob';

-- Lock held on Bob

UPDATE Accounts SET balance = balance + 200 WHERE name = 'Alice'; -- Causes Deadlock



✅ Observation:



Both sessions hold different locks and wait for each other.



Database detects deadlock → rolls back one transaction.



📸 Screenshot: SQL deadlock message (one transaction aborted).



📘 Explanation:

Deadlocks happen when two transactions hold resources the other needs.

The DBMS automatically detects and resolves it by aborting one.



🪵 Task 3️⃣: Log-Based Recovery



Most modern databases (MySQL, PostgreSQL, SQL Server) maintain transaction logs:



Binary Log / WAL (Write-Ahead Log) records every change before committing.



🧩 Step 1: Start and Rollback a Transaction

BEGIN TRANSACTION;

UPDATE Accounts SET balance = balance + 300 WHERE name = 'Charlie';

ROLLBACK;



🧩 Step 2: Check Logs



If using MySQL:



SHOW BINARY LOGS;

SHOW BINLOG EVENTS;



If using PostgreSQL:



SELECT * FROM pg_stat_activity;



✅ You’ll see entries for the UPDATE followed by a ROLLBACK (UNDO) event.



📸 Screenshot: Log entries showing rollback.



📘 Explanation:

The transaction log helps recover or rollback uncommitted operations after crashes — ensuring data consistency.



📚 Part 2 — Indexing, Hashing & Query Optimization



Now let’s explore how indexes make your queries lightning fast ⚡



🧱 Step 1: Create Table and Insert Data

CREATE TABLE Students (

roll_no INT PRIMARY KEY,

name VARCHAR(50),

dept VARCHAR(10),

cgpa DECIMAL(3,2)

);



🧩 Step 2: Insert 20 Sample Records

INSERT INTO Students VALUES

(101, 'Arun', 'CSE', 8.7),

(102, 'Meena', 'ECE', 7.9),

(103, 'Vishal', 'CSBS', 8.3),

(104, 'Priya', 'IT', 9.0),

(105, 'Ravi', 'CSBS', 8.5),

(106, 'Swetha', 'MECH', 7.8),

(107, 'Deepak', 'EEE', 6.9),

(108, 'Ananya', 'CSE', 9.1),

(109, 'Balaji', 'IT', 8.4),

(110, 'Hari', 'CSBS', 8.9),

(111, 'Nisha', 'ECE', 7.4),

(112, 'Sanjay', 'MECH', 8.0),

(113, 'Keerthi', 'CSE', 9.3),

(114, 'Suresh', 'CSBS', 8.0),

(115, 'Gayathri', 'EEE', 8.4),

(116, 'Kavin', 'IT', 7.6),

(117, 'Lavanya', 'CSE', 8.8),

(118, 'Karthik', 'CSBS', 9.2),

(119, 'Rohit', 'MECH', 8.1),

(120, 'Preethi', 'ECE', 8.0);



📸 Screenshot: 20 records inserted.



🌲 Step 3: Create a B-Tree Index on roll_no

CREATE INDEX idx_rollno_btree ON Students (roll_no);



Now query:



SELECT * FROM Students WHERE roll_no = 110;



📘 Explanation:

B-Tree index improves performance of equality and range lookups on numeric fields.



📸 Screenshot: Query output for roll_no = 110.



🌳 Step 4: Create a B+ Tree Index on cgpa



(In most SQL databases, normal indexes are internally implemented as B+ Trees)



CREATE INDEX idx_cgpa_bplustree ON Students (cgpa);



Query:



SELECT * FROM Students WHERE cgpa > 8.0;



✅ Retrieves high-scoring students efficiently.



📸 Screenshot: Output for cgpa > 8.0.



⚡ Step 5: Create a Hash Index on dept

CREATE INDEX idx_dept_hash ON Students USING HASH (dept);



Now run:



SELECT * FROM Students WHERE dept = 'CSBS';



✅ Fast equality search on department names.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Database System Internals — Transactions, Deadlocks, Recovery & Indexing Explained with SQL Examples

Thematisch verwandte Begriffe: Database, System, Internals, Transactions · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-5695 | Arbitrary file upload vulnerability due to a lack of proper validation in…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick