Abstract: Once upon a time, you inherited an application or a database that was filled with chaos and inconsistencies. The T-SQL code is overly complex and impossible to ken. The architecture is painful to behold, and grueling to code for. One might optimistically say that query performance is “spectacularly mediocre”. If you’re without good documentation or system architects to guide you, how do you break the curse of confusion? In this session you’ll learn several methods for conquering chaotic code, and how to seek and destroy some of the nastier coding mistakes and inefficiencies. We will break complicated queries into key pieces, turn them upside-down, and reform them into something sensible. We will vanquish major issues like data abuse and index negligence. We will restructure joins, tame subqueries, and refactor dynamic SQL. We will emerge victorious!