#BESTWORSTCODE

Last month, on April 24th, Redgate hosted the #BESTWORSTCODE contest. Unfortunately, I wasn’t able to participate at the time. Better late than never, I suppose. Erik Darling blogged about his example recently. This gave me an idea of something really dumb I could do. PIVOT/UNPIVOT You might be able to take a guess at where…

DROP [IF EXISTS]

What is it? Microsoft introduced a new method of dropping objects in SQL Server 2016. There are many times we want to conditionally drop objects to prevent errors or to allow scripts to be idempotent. Without first checking if the object exists, and it turns out it doesn’t exist, the DROP statement would fail. DROP…

BULK INSERT & CHECK Constraints

There are a few occasions where BULK INSERT seems to be a great solution for loading data from flat files. Sure, there are alternatives. You could also use BCP or SSIS, but BULK INSERT can come in handy in a time crunch. I don’t use this too often, but in the right circumstances, this could…

Introduction to Filtered Indexes

Filtered indexes were introduced in SQL Server 2008, providing us with the ability to save space and potentially improve performance. These indexes are nonclustered, meaning they essentially make a “copy” of our underlying data in a B-tree structure. The primary difference from creating a traditional nonclustered index, is the inclusion of a WHERE clause. So,…