Deadlock and Trace Flags 1204 and 1222

When you are looking for deadlocks there are, like most things in SQL Server, more than one way to find the deadlocks. This article is specifically focused on using the SQL Server ERRORLOG file located in the LOG directory for the SQL instance. If you used the defaults on SQL Server 2012, this log would be at this location:

C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Log\ERRORLOG

For SQL Server 2014 it would be here:

C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\Log\ERRORLOG

and in similar locations for other versions of SQL Server.

 

What is a Deadlock?

deadLock

A deadlock is a specific case in SQL Server and other databases where, in the simple case of two transactions, the first transaction gets stuck waiting on blocking from the second transaction, and the second transaction gets stuck waiting on blocking for the first transaction.

Imagine traffic so jammed up that one lane of travel is blocking another lane of travel, and vice versa. The deadlock in SQL Server is similar to this, but instead of traffic being blocked, it is queries and transactions being blocked.

Eventually in traffic when cars are blocking, one will give up and back out, and the other will be allowed to drive through. The one that backs out is known as the deadlock victim.

When one query is chosen as the deadlock victim, it looks something like this:

Read more of this post

Difference Between TRUNCATE TABLE and DELETE FROM Table

Most DBAs know the usual difference between TRUNCATE and DELETE FROM, however one not so obvious difference between the two is how things are handled if the table is corrupt.

For instance, if you look at the corrupt database from the Database Corruption Challenge Week 1, you see the following

DeleteVsTruncate1

If you want to clear out the corrupt Revenue table, one way to attempt to do it is with a DELETE statement like this.

Read more of this post

Newsletter Mailing List Added

With all the interest in the Database Corruption Challenge, and the hundreds of email message I have exchanged with people over the last 3 days relating to the Database Corruption Challenge, I have decided to set up a newsletter mailing list to use to notify people of the upcoming Database Corruption Challenges, and other interesting tidbits.

Sign up for the newsletter to get notified of upcoming Database Corruption Challenges. You will get notified ahead of time when the corruption challenge will be posted.

I would love to contact everyone individually, however the list of people interested in the Corruption Challenge is getting to big to easily manage.

Just click here to go to the newsletter signup form.

What if I don’t want to subscribe to the newsletter?

That’s no problem, I will be announcing the Database Corruption Challenge on Twitter after it is posted. Just follow me on Twitter  @sqlEmt, and watch for updates.

Will you spam me?

No. You will only receive information related to SQL Server topics, like the corruption challenge, like Database Health Monitor, my and company (Stedman Solutions), blog posts, things like that. If you end up getting too much email, it is easy to unsubscribe.

Will you sell my email address?

No your email address will be used by my, and my company Stedman Solutions, LLC. The only way that your email address would be sold would be if someone was to purchase my entire company Stedman Solutions, LLC. which is very unlikely at this point.

Just click here to go to the newsletter signup form.

 

Related Links:

A Weekend Full of Database Corruption

On Saturday morning, I announced the Database Corruption Challenge, and I had to abbreviate it as the DBCC, why not, acronym overloading isn’t always a bad thing.

There were 91 participants, 22 of which ended up with correct answers with no corruption and no data loss.

I created a database, with 3 bytes of corruption in one of the leaf node pages of a clustered index, however all I stated was that the database was corrupt, and it could be fixed with no data loss.

The number of different ways that people solved the problem was amazing. There were many attempts that did remove the corruption, and did recover all the rows, however many judged success as having the same number of rows as before, as a success. There were so many successful solutions that I think I will post one a day for the rest of the week, with the details explained. One solution even involved editing the database file on disk with a hex editor. I don’t have time to post all the good solutions right now.

 

The original corrupt database had been created on SQL Server 2014, but many people contacted me stating that they didn’t have SQL Server 2014 on their home computer, so I ended up creating a SQL Server 2008 version of the problem, but some were so driven to solve the challenge that they ended up installing SQL Server 2014 just to work the problem.

house1

Nice work John. Thanks for playing along, I hope you enjoyed the experience.  The next tweet from Mike Fal followed the post from John Morehouse.

nerd2

 

I hope that John took this comment from Mike Fal as a great compliments, however it was soon corrected by AJ Mendo that it is more geek than nerd.

aj1

Either way, geeks or nerds, it was a good learning experience for those involved, and for me having to evaluate each solution to determine if it was indeed a valid solution with no data loss. Personally I ended up restoring the corrupt database and testing different solutions over 50 times this weekend.

Read more of this post

SQL Server 2008 Downloads for the Database Corruption Challenge (DBCC) Week 1

After introducing the Database Corruption Challenge (DBCC) – Week 1 Challenge yesterday, I received several requests for a SQL Server 2008 version of the challenge. Here is is, and for future Database Corruption Challenges, I will include a SQL Server 2008 version of the challenge.  The 2008 backup file should restore just fine on SQL 2008, SQL Server 2008R2, SQL Server 2012, and SQL 2014. However if you are using SQL Server 2014 you can download the SQL Server 2014 specific backup file instead.

CorruptionChallenge1_2008.zip

 

For more details see the Database Corruption Challenge (DBCC) – Week 1 Challenge.

 

To see the winning solution and list of winners visit the “Weekend of Corruption” blog post.

Introducing the DataBase Corruption Challenge (DBCC) – Week 1 Challenge

corruption

Welcome to the DataBase Corruption Challenge, this is an about weekly blog challenge where I will post a corrupt SQL Server database with some details on what happened to it.

If at this point you are already a bit irked by my use of capitalization in the DataBase Corruption Challenge, and the acronym of DBCC that I have used to describe it, then you are already ahead of many people reading about this challenge. Welcome to the challenge.
The challenge will be to download the corrupt database and attempt to recover it. If you can recover it, please send me the steps to recover it, along with some proof that the database has been recovered. The goal each week will be the following:

Read more of this post