DEADLOCK
DEADLOCK is a SQL statement in the Transactions category. A situation where two transactions block each other, each waiting for the other to release a lock. The syntax is -- Deadlock occurs when two transactions each hold locks the other needs.. It returns error (deadlock victim). A typical example: -- Transaction 1: UPDATE accounts SET balance = balance - 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; -- Waits for T2 -- Transaction 2: UPDATE accounts SET balance = balance - 50 WHERE id = 2; UPDATE accounts SET balance = balance + 50 WHERE id = 1; -- Waits for T1 -- Database detects deadlock and kills one transaction… A close relative is BEGIN / START TRANSACTION, which begins a new transaction. Changes made within are invisible to others until COMMIT. A close relative is COMMIT, which saves all changes made in the current transaction permanently.