So far, we have been learning the building blocks of writing T-SQL code: T-SQL basics, query optimization fundamentals, reading and interpreting query plans, and some general best practices around indexing and writing efficient T-SQL code. By this point, we should have a good understanding of how to write an efficient query, but there are some common pitfalls that even experienced T-SQL developers can encounter that will make a query perform poorly.
In this chapter, we will examine some common T-SQL patterns and anti-patterns, specifically those that should be easily identified just by looking at the T-SQL code. We will cover the following topics:
- The perils of SELECT *
- Functions in our predicate
- Deconstructing Table-Valued Functions
- Complex expressions
- Optimizing OR logic
- NULL means unknown
- Fuzzy string matching
- Inequality logic
- EXECUTE...