Quantcast
Channel: T-SQL Queries Archives - SQLPerformance.com
Browsing all 90 articles
Browse latest View live

Nested window functions in SQL

The ISO/IEC 9075:2016 standard (SQL:2016) defines a feature called nested window functions. This feature allows you to nest two kinds of window functions as an argument of a window aggregate function....

View Article


Image may be NSFW.
Clik here to view.

T-SQL bugs, pitfalls, and best practices – window functions

This article is the fourth installment in a series about T-SQL bugs, pitfalls and best practices. Previously I covered determinism, subqueries and joins. The focus of this month's article is bugs,...

View Article


Image may be NSFW.
Clik here to view.

T-SQL bugs, pitfalls, and best practices – pivoting and unpivoting

This article is the fifth part in a series about T-SQL bugs, pitfalls and best practices. Previously I covered determinism, subqueries, joins, and windowing. This month, I cover pivoting and...

View Article

Overlooked T-SQL Gems

My good friend Aaron Bertrand inspired me to write this article. He reminded me of how sometimes we take things for granted when they seem obvious to us and don't always bother checking the full story...

View Article

Image may be NSFW.
Clik here to view.

Analyzing "death by a thousand cuts" workloads

There are multiple methods to look at poorly performing queries in SQL Server, notably Query Store, Extended Events, and dynamic management views (DMVs). Each option has pros and cons. Extended Events...

View Article


Image may be NSFW.
Clik here to view.

Row numbers with nondeterministic order

The ROW_NUMBER window function has numerous practical applications, well beyond just the obvious ranking needs. Most of the time, when you compute row numbers, you need to compute them based on some...

View Article

Image may be NSFW.
Clik here to view.

Filtered Indexes and Forced Parameterization (redux)

After blogging about how filtered indexes could be more powerful, and more recently about how they can be rendered useless by forced parameterization, I'm revisiting the filtered...

View Article

Image may be NSFW.
Clik here to view.

NULL complexities – Part 1

NULL handling is one of the trickier aspects of data modeling and data manipulation with SQL. Let's start with the fact that an attempt to explain exactly what a NULL is is not trivial in and of...

View Article


NULL Complexities – Part 2

This article is the second in a series on NULL complexities. Last month I introduced the NULL as SQL's marker for any kind of missing value. I explained that SQL doesn't provide you with the ability to...

View Article


Image may be NSFW.
Clik here to view.

Strongly Type Those Table-Valued Parameters

Table-valued parameters have been around since SQL Server 2008 and provide a useful mechanism for sending multiple rows of data to SQL Server, brought together as a single parameterized call. Any rows...

View Article

Image may be NSFW.
Clik here to view.

NULL complexities – Part 3, Missing standard features and T-SQL alternatives

This article is the third installment in a series on NULL complexities. In Part 1 I covered the meaning of the NULL marker and how it behaves in comparisons. In Part 2 I described the NULL treatment...

View Article

Image may be NSFW.
Clik here to view.

NULL complexities – Part 4, Missing standard unique constraint

This article is Part 4 in a series about NULL complexities. In the previous articles (Part 1, Part 2, and Part 3), I covered the meaning of the NULL as a marker for a missing value, how NULLs behave in...

View Article

Image may be NSFW.
Clik here to view.

Please help with STRING_SPLIT improvements

We're mid-cycle between releases, where we're not yet hearing about any of the features planned for SQL Server vNext. This is probably the best time to press Microsoft for improvements, as long as we...

View Article


Fundamentals of table expressions, Part 1

This article is the first in a series about the fundamentals of table expressions in T-SQL. I will mainly focus on four types of named table expressions, which are known in T-SQL as derived tables,...

View Article

Image may be NSFW.
Clik here to view.

Visualizing the Tipping Point with Plan Explorer

The tipping point is a term I first heard used by SQL Server performance tuning guru and long-time SentryOne Advisory Board member Kimberly Tripp – she has a great blog series on it here. The tipping...

View Article


Fundamentals of table expressions, Part 2 – Derived tables, logical...

Last month I provided a background to table expressions in T-SQL. I explained the context from relational theory and the SQL standard. I explained how a table in SQL is an attempt to represent a...

View Article

Image may be NSFW.
Clik here to view.

Fundamentals of table expressions, Part 3 – Derived tables, optimization...

In Part 1 and Part 2 of this series, I covered the logical, or conceptual, aspects of named table expressions in general, and derived tables specifically. This month and the next I’m going to cover the...

View Article


Image may be NSFW.
Clik here to view.

Fundamentals of table expressions, Part 4 – Derived tables, optimization...

This article is the fourth part in a series on table expressions. In Part 1 and Part 2 I covered the conceptual treatment of derived tables. In Part 3 I started covering optimization considerations of...

View Article

Image may be NSFW.
Clik here to view.

Fundamentals of table expressions, Part 5 – CTEs, logical considerations

This article is the fifth part in a series about table expressions. In Part 1 I provided the background to table expressions. In Part 2, Part 3, and Part 4, I covered both the logical and the...

View Article

Image may be NSFW.
Clik here to view.

Please stop using this UPSERT anti-pattern

ul.f { margin-bottom:0px!important; } I think everyone already knows my opinions about MERGE and why I stay away from it. But here's another (anti-)pattern I see all over the place when people want to...

View Article
Browsing all 90 articles
Browse latest View live