T-SQL and Database Development

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

478 associated posts232 primary posts

The 6 Best Things Microsoft Ever Did to SQL Server

This entire blog post is driven by the #1 feature in this list. I think about the #1 feature a lot, like at least once a week. I think about it so much that I had to stop and think about what other similar great things Microsoft has done over the years, and be thankful for what a nice platform this is to work with. Let's go through 6 of my favorite Microsoft decisions.

Read more about The 6 Best Things Microsoft Ever Did to SQL Server 46 comments — Join the discussion
T-SQL & Development

Can AI Rewrite Bad Queries in Seconds? Kinda.

When I see horrific code, stuff that would take a lot of manual labor to fix, I like to lob it over to an LLM like ChatGPT just to see how it does.

For example, on a call with a client, I opened up one of their slowest pieces of code to find that it was running a cursor, processing data row by row rather than working in sets. To simulate it, I've written up a few stored procedures against the Stack Overflow database:

Read more about Can AI Rewrite Bad Queries in Seconds? Kinda. 13 comments — Join the discussion
T-SQL & Development

I Feel Sorry for Untrained Developers Using Entity Framework.

Most of the time, I love Entity Framework, and ORMs in general. These tools make it easier for companies to ship applications. Are the apps perfect? Of course not - but they're good enough to get to market, bring in revenue to pay salaries, and move a company forwards.

However, just like any tool, if you don't know how to use it, you're gonna get hurt.

Read more about I Feel Sorry for Untrained Developers Using Entity Framework. 23 comments — Join the discussion

[Video] Office Hours in Osaka, Japan

Kon'nichiwa! My vacation tour continues in Osaka, Japan, a city famous for its street food, nightlife, and host and hostess clubs. I'm usually the kinda guy who does classy dinners at 5PM and then hits the sack by 9PM at the latest, so you might wonder how I got here. The answer is that Yves planned this trip out, hahaha, so here we are. As long as we're here, let's go through your top-voted questions from https://pollgab.com/room/brento.

Read more about [Video] Office Hours in Osaka, Japan 9 comments — Join the discussion
Performance Tuning

Query Exercise: Why Are These 3 Estimates So Wrong?

Our prior Query Exercise introduced SQL Server's 201 buckets problem: its inability to accurately estimate rows for more than 201 outliers in a table. I followed up with a solution using filtered statistics to help with the next 200 outliers, and I talked about how that's really overkill for the simple problem we were facing in that initial challenge.

Read more about Query Exercise: Why Are These 3 Estimates So Wrong? 6 comments — Join the discussion
Performance Tuning

Query Exercise Answers: Solving the 201 Buckets Problem

In this week's Query Exercise challenge, I explained SQL Server's 201 buckets problem. SQL Server's statistics only handle up to ~201 outliers, which means that outliers ~202-300 get wildly inaccurate estimates.

In our example, I had an index on Location and perfectly accurate statistics, but even still, this query gets bad estimates because Lithuania is in outliers ~202-300:

Read more about Query Exercise Answers: Solving the 201 Buckets Problem 8 comments — Join the discussion