Deadlock in Databases

From databases perspective, a deadlock is a phenomenon that occurs when two transactions are blocking each other.

In the figure above, we have a classic deadlock situation. Transaction A (old man transaction) holds a lock to resource A (Dogs), but it doesn't release it until it will acquire a lock to resource B (Cats) that is currently locked by transaction B (young man transaction). In the same time, transaction B (young man transaction) holds a lock to resource B (Cats), but it doesn't release it until it will acquire a lock to resource A (Dogs) that is currently locked by transaction A (old man transaction).