Writing Elegant T-SQL Queries
At this point, we should have a good understanding of how to build a T-SQL query, and the building blocks of writing T-SQL code such as query optimization fundamentals, reading and interpreting query plans, and some best practices around indexing and writing efficient T-SQL code. But how do we build an elegant T-SQL query? One that not only gets the job done but does so efficiently?
There are a few guidelines that are important to keep in mind when writing T-SQL queries to ensure that they perform and scale well while avoiding 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’re going to cover the following main topics:
- Best practices for T-SQL querying
- The perils of SELECT *
- Functions in our predicate...