As a result, the deadlock is broken and now the remaining process has the ability to gain access to the service or to the instance that it was attempting to access. The lock manager will then initiate and send a 1205 error message to the client it has chosen as the victim and then it will kill that process ID. The lock manager's thread will check for deadlocks on the system and when its detection algorithm detects a deadlock, it will choose one of the processes using the server's process ID and it will designate that as a victim. In this example to solve a deadlock, we see process one and process two, both in a deadlock on the SQL server. So therefore process number one and process number two may each be waiting for the same resource but there's a lock held by the other resource so we have a deadlock situation. Now a deadlock is essentially an instance where two processes are each waiting for a resource that is held by the other process. So basically in a normal server environment, infrequent blocking locks are acceptable but if the blocking locks become common, or become more widespread, then there is probably some kind of a design or query implementation problem and you should do a design check of the database indexes or queries. The current process must end before the new one can begin its processing. Blocking is another type of lock which occurs when one lock causes another process to wait in a holding queue. Minimizing the locks will increase your database performance according to how the users see things in terms of the performance of the database. So therefore when you're doing the reads, inserts, updates and deletes, the rows are typically locked and the transactions that are taking place must wait for the current transaction to finish. A dirty read would be an example of somebody checking the balance and finding there to be 100 dollars in the bank account while at the same time somebody was making a withdrawal of 75 dollars in which case the actual balance would only 25 and if you were attempting to do a withdrawal of another amount such as 50 dollars, there would be conflict on the system. They're designed to prevent "dirty reads." Now essentially what we mean by this, consider a bank account balance where there may be the potential of a deposit and a withdrawal or a balance transaction and a withdrawal taking place simultaneously.
![sql balance lock sql balance lock](https://i.ytimg.com/vi/PhUgUTutiGk/maxresdefault.jpg)
![sql balance lock sql balance lock](https://image.slidesharecdn.com/isolationlevels-181212192509/95/locks-blocks-and-snapshots-maximizing-database-concurrency-new-england-sql-user-group-12-638.jpg)
![sql balance lock sql balance lock](https://d2vlcm61l7u1fs.cloudfront.net/media/1e9/1e9d113f-fe45-4afe-b6c4-022cff897c30/phpjL55pf.png)
They occur during reads, insertions, updates and deletes and they prevent concurrent use by different transactions. Locks are held on SQL server resources such as rows. In this video, we'll focus on performance impacts on your SQL instance by discussing what locks, blocking and deadlocks are and how they impact users of your database.