When you inherit an application or a database, you often become the proud owner of overly complex, poorly performing T-SQL code. These queries rarely come equipped with meaningful documentation or with system architects who are willing and able to explain the code.
This chapter covers several methods to make sense of the mess. The overall approach is to organize, break down, and then streamline the code to identify and remove some of the nastier coding mistakes and inefficiencies.
The sample database is a small model of a vending machine business, called VendCo. Tables in the VendUnit schema store data about each vending machine (including model and location information) and ...