How to Eat a SQL Elephant in 10 Bites

One byte at a time, obviously! No elephants were harmed during photoshopping. Sometimes, when you have to optimize a poor performing query, you may find yourself staring at a huge statement, wondering where to start. Some developers think that a single elephant statement is better than multiple small statements, but this is not always the case. Let’s try to look from the perspective of software quality: Efficiency The optimizer will likely come up with a suboptimal plan, giving up early on optimizations and transformations. [Read More]

Mirrored Backups: a useful feature?

One of the features found in the Enterprise Edition of SQL Server is the ability to take mirrored backups. Basically, taking a mirrored backup means creating additional copies of the backup media (up to three) using a single BACKUP command, eliminating the need to perform the copies with copy or robocopy. The idea behind is that you can backup to multiple locations and increase the protection level by having additional copies of the backup set. [Read More]

Setting up an e-mail alert for DBCC CHECKDB errors

Some months ago I posted a script on a SQLServerCentral forum to help a member automating the execution of DBCC CHECKDB and send and e-mail alert in case a consistency error is found. The original thread can be found here. I noticed that many people are actually using that script and I also got some useful feedback on the code itself, so I decided to write this post to make an enhanced version available to everyone. [Read More]

Discovering resultset definition of DBCC commands

Lots of blog posts and discussion threads suggest piping the output of DBCC commands to a table for further processing. That’s a great idea, but, unfortunately, an irritatingly high number of those posts contains an inaccurate table definition for the command output. The reason behind this widespread inaccuracy is twofold. On one hand the output of many DBCC commands changed over time and versions of SQL Server, and a table that was the perfect fit for the command in SQL Server 2000 is not perfect any more. [Read More]

Concatenating multiple columns across rows

Today I ran into an interesting question on the forums at SQLServerCentral and I decided to share the solution I provided, because it was fun to code and, hopefully, useful for some of you. Many experienced T-SQL coders make use of FOR XML PATH(‘’) to build concatenated strings from multiple rows. It’s a nice technique and pretty simple to use. For instance, if you want to create a list of databases in a single concatenated string, you can run this statement: [Read More]