Deadlock in concurrent transactions happen when two or more transactions keep waiting for a particular resource in the database. To understand this, refer to the diagram given below. Here, Transaction 1 updates Table 1 and acquires an exclusive lock with Table 1. Meanwhile, Transaction 2 updates Table 2 and acquires an exclusive lock with Table 2. Then, Transaction 2 tries to update Table 1, but it has to wait because Transaction 1 already has an exclusive lock with Table 1. Now, Transaction 1 tries to update Table 2, but it has to wait because Transaction 2 already has an exclusive lock with Table 2. So, the two transactions will keep waiting on forever until something happens and breaks the deadlock.
Solution for deadlocks: To overcome deadlocks, database management system keeps checking the locks over a period of time and when it finds that two or more transactions are in a deadlock, it randomly picks a deadlock loser and rolls back the transaction, thus freeing the deadlock. The transaction which was rolled back, receives and error code that the transaction was failed. This transaction can be tried again after some time.