How Does Deadlock Occur in Database

How Does Deadlock Occur in Database

In a database, a deadlock is a situation in which two or more transactions are waiting for one another to give up locks. For example, Transaction A might hold a lock on some rows in the Accounts table and needs to update some rows in the Orders table to finish.

How does deadlock occur in MySQL?

A deadlock in MySQL happens when two or more transactions mutually hold and request for locks, creating a cycle of dependencies. … InnoDB automatically detects transaction deadlocks, rollbacks a transaction immediately and returns an error.

How can avoid deadlock in SQL Server?

  1. Try to keep transactions short; this will avoid holding locks in a transaction for a long period of time.
  2. Access objects in a similar logical manner in multiple transactions.
  3. Create a covering index to reduce the possibility of a deadlock.
Chloe Bennett
Author

Chloe Bennett

Chloe Bennett explores the intersection of pop culture, streaming entertainment, digital trends, and contemporary lifestyle. Her weekly commentary reaches thousands of culture enthusiasts.