Press "Enter" to skip to content

Category: T-SQL

What Was New for SQL Developers in 2012

Jeff Taylor starts a retrospective:

In my session, “What’s New in SQL Server for the Developer”, I always start with a show of hands, and usually the room has everything from SQL Server 2000 all the way up to 2025, and a few folks running Azure SQL. That’s a big spread. It’s also exactly why I built the session the way I did. A lot of us are still writing T-SQL like it’s 2008, even though the engine underneath has had better tools for years.

So I’m turning my session into a series, one post per version, with the examples from my slides. Today we start where the session starts: SQL Server 2012.

I love this approach. I have a very similar talk to Jeff’s, though, for the sake of time, I have my starting point as “2016 and a couple of things that were really important in 2012.”

Leave a Comment

Fuzzy String Matching now GA

Abhiman Tiwari promotes a feature:

MICROSFT isn’t MICROSOFT. MARHTA isn’t MARTHA. INV-1O08 isn’t INV-1008. To an equality check, each pair is simply different. To your business, each is a near miss worth catching.

Today, fuzzy string matching is generally available in Microsoft SQL. EDIT_DISTANCE tells you MICROSFT is one edit from MICROSOFT. JARO_WINKLER_SIMILARITY scores MARTHA and MARHTA at 96 out of 100. It all runs in T-SQL, right where your data lives, with no external libraries, models, or custom code.

As of CU11, this is now GA in SQL Server 2025.

Leave a Comment

IS DISTINCT FROM

Andy Brownsword tries out a shortcut:

Comparisons involving NULL-able values and columns are an early learning experience. I recently stumbled upon a relatively new way to handle these which I thought would be interesting T-SQL to share.

I think the two reasons you don’t see this in production are as follows. First, it requires a recent version of SQL Server, 2022 or later. A lot of the T-SQL code that went into training language models was for older versions of SQL Server. Second, because there’s no performance difference, people don’t spend a lot of time changing existing code to use this syntax. It’s a bit clearer in terms of intent, but otherwise doesn’t move the needle for people.

Leave a Comment

Managing tempdb Activity

Aaron Bertrand has built a solution:

Managing tempdb growth tends to be a very reactive exercise. We size tempdb using a predictive ruleset based on expected workload, database size, concurrency, and other imperfect factors. Then someone does something silly and fills the T: drive. If we catch it in time, we may be able to kill the offending session or add space to prevent the workload from dying. Then we tell them not to do it again; but they will, of course, so we expand the drive again and hope this time it’s big enough. But it rarely is. It’s like a baseball game that’s tied in the 5,662nd inning. Each team keeps scoring a single run in every new inning; the game will never end.

Our existing “drive full” alarms start going bonkers as soon as a drive is more than 90% full. We have a dedicated drive for tempdb data, and we pre-allocate the data files to just under 90% of the available space. This prevents any growth events while they’re using tempdb within the bounds of its current size. But when we fill the space already allocated to the data files, they grow. After one or two growths, we have crossed the threshold for drive space alerts, and it probably won’t be long before the volume fills and the workload grinds to a halt.

Click through for the solution scripts and Aaron’s explanation of it all.

Leave a Comment

The Limits of CHOOSE()

Steve Jones performs a test:


I was looking over the CHOOSE() function while editing an article at SQL Server Central. I realized there isn’t a documentation note on how many parameters can be included. I decided to test.

This post looks at the tests and results.

Click through to see how many parameters Steve was able to cram in before the whole thing fell apart. This is definitely a place where Swart’s 10% Rule comes into play.

Comments closed

ROLLUP, CUBE, and GROUPING SETS in T-SQL

Louis Davidson works with three amigos:

To get the total, there are a few ways, which I will demonstrate in the next sections on the aggregation functions, ROLLUP, CUBE, and then GROUPING SETS. Grouping sets are the most flexible, in that they let you do what the other two can do, but with more control. But knowing the others is important because it is how most ad hoc queries will be written.

It’s uncommon that I use GROUPING SETS() in my code, but every time I do, I’m thankful that it exists.

Comments closed

XACT_ABORT vs TRY_CATCH

Jared Westover explains the difference:

After creating a SQL script and a pull request, a savvy developer left a comment on the PR because they were confused about why I was using both XACT_ABORT and TRY…CATCH. They thought that including both in one script was redundant. That got me thinking: is it true that setting XACT_ABORT ON makes TRY…CATCH redundant?

The most interesting part of this post is the cases in which you would use both in the same script.

Comments closed