

It says over there, hey I was chosen as the deadlock victim.
Sql server deadlock error update#
The update completes successfully but oh look, our select query has fallen victim to the deadlock. Beause if I committed it, when I went to go update again, and again, it wouldn’t find the same row. The reason that I’m not committing our transaction is just to make this whole thing re-runnable so that you can do this over and over. They start up their query, and as you can see, it’s not finishing up super fast, it’s blocked by our first update.īack in our first session, we go to do the second update, and notice that I even have a ROLLBACK at the end of this. Now, this query isn’t anything too nefarious, we’re just looking for some aggregate information from a view named dbo.V_CustomerOrders. What we’ve done so far is: in session one, it’s opened a transaction and it’s run this first update, but before it gets to the second one, a user comes in and they’re running a report. So I’m going to copy it, I’m going to open up a new session, paste that in, and just for convenience I’m going to put it in a new vertical tab group, so we can see them side by side. You have this at the bottom of your script.

In our first session here, we begin our transaction and then run the first update.īefore that transaction can complete, though, another query starts up in a totally different session. The deadlock happens when things go like this. I’m going to use the database, and in our first session, we’ve got a transaction that has two update statements in it. As you can see, Contoso restores super fast. Depending on where you put the backup file and how your test instance is set up, you may need to change some of those drive letters and folders. I have it set up with the drives on my test instance.
Sql server deadlock error download#
It’s not super huge, I’ve got the URL for you to download it in the script, as well as steps to restore the database. This demo uses Contoso Retail Data Warehouse, which is a Microsoft sample database. Here I am in Management Studio and the first thing you get in the problem file is information on the demo database and where to get it. In the problem SQL file, I give you the steps to reproduce the deadlock, and I’m going to show you how this deadlock plays out right now. I’m giving you a copy of the deadlock graph and even more. There is more than one way to defuse this deadlockįor extra credit, you can find a second way– and by finding a second way, I don’t mean just creating the same index definition with a different name. And in fact, you can create more than one index. You’re not allowed to change the queries involved, you’re not allowed to change their isolation levels, or the isolation level on the database, you need to defuse the deadlock just by creating an index. You need to defuse the deadlock by creating an index. Your challenge today is to take a deadlock and figure out: how can I prevent this deadlock from happening? Welcome to the SQLChallenge, Defuse the Deadlock.
