T-SQL and Database Development

Writing, reviewing, debugging, and maintaining T-SQL and database code.

478 associated posts232 primary posts

T-SQL & Development

T-SQL Tuesday Roundup: You Know A Query’s Gonna Be Bad When…

For this month's T-SQL Tuesday, I invited y'all to tell me how you know a query's gonna be bad when you open it. Riccardo Perico and Shane O'Neill says WHILE loops and/or CURSORs are pretty good indicators. I agree, because especially when you're opening code in the year 2026, and someone still hasn't figured this out…

Read more about T-SQL Tuesday Roundup: You Know A Query’s Gonna Be Bad When… 11 comments — Join the discussion

How to Format Your Queries in SSMS

Microsoft SQL Server Management Studio 22.7 added the ability to format your T-SQL queries by right-clicking and clicking Format SQL, or by hitting control-K, control-Q on your keyboard:

You're probably not going to like the default formatting out of the box because you're the kind of person who has strong, passionate feelings and likes to argue about them on the Internet. Good news! The configurations are really flexible. Go into Tools, Options, SQL Formatter:

Read more about How to Format Your Queries in SSMS 10 comments — Join the discussion

You Can’t Trust “Edit Query Text” in SSMS’s Execution Plans.

When there are IF branches or conditional logic, "Edit Query Text" only shows you the branches that actually executed. It's easy to miss whole swaths of code that didn't happen to execute one particular time.

To demo it, let's create a simple stored procedure with an IF branch that sometimes executes, and sometimes doesn't:

Read more about You Can’t Trust “Edit Query Text” in SSMS’s Execution Plans. Be the first to comment

SSMS v22.4.1: Copilot is GA. So What’s It Do Right Now?

Copilot in SSMS has two parts. Usually people focus on the pop-out Copilot chat window, and that's useful for sure, but honestly I think you're going to get way more mileage out of the code completions feature, right away, because it blends in with your existing workflows. Let's say that I'm working with the Stack…

Read more about SSMS v22.4.1: Copilot is GA. So What’s It Do Right Now? 14 comments — Join the discussion

How to Help Copilot Encourage Good Database Standards

I know a lot of y'all lag behind on upgrading SSMS, but v22.3 just introduced something that you need to be aware of. It's going to impact any of your users who DO upgrade their SSMS, or who use Github Copilot. There's something that you can do in order to improve Copilot's code quality and make it match your preferred coding standards.

Read more about How to Help Copilot Encourage Good Database Standards 13 comments — Join the discussion
T-SQL & Development

Update: SQL Server 2025’s REGEX Performance Isn’t So Bad!

Back in March 2025 when Microsoft first announced that REGEX support was coming to SQL Server 2025 and Azure SQL DB, I gave it a quick test, and the performance was horrific. It was bad in 3 different ways:

The CPU usage was terrible, burning 60 seconds of CPU time to check a few million rows
It refused to use an index
The cardinality estimation was terrible, hard-coded to 30% of the table

Read more about Update: SQL Server 2025’s REGEX Performance Isn’t So Bad! 14 comments — Join the discussion