BackendQuestion 10 of 52
Handling Deadlocks
Problem
Transaction A locks Table 1 and wants Table 2. Transaction B locks Table 2 and wants Table 1. Both are stuck waiting forever, and the database forcefully kills one of them. You need to train the junior devs to avoid this. Write a query that outputs solution with the value: "To prevent deadlocks, ensure transactions always acquire locks on resources in the same order."
Database Schema
This problem acts as a scratchpad. You will write your own DDL/DML or conceptual queries, so there is no predefined schema.
Try It
Loading playground environment...