Press "Enter" to skip to content

Curated SQL Posts

Working with Group Managed Service Accounts in SQL Server

Aleksey Vitsko uses a gMSA:

I plan to install several SQL Server instances across different servers. On all servers, I would like to use the same accounts for the SQL Server services for easier management. I’ve heard there are Group Managed Service Accounts (gMSA) that can be used as SQL Server service accounts, for example for the database engine service and SQL Agent service. How can I configure gMSAs?

Click through for a good solution to a security problem that becomes all the more important when you need high availability.

Leave a Comment

Wrong Outer Joins

Aaron Bertand only likes the right kind, by which I mean the left kind:

The headline is probably unfair and is not meant to imply that a RIGHT OUTER JOIN is wrong. But when I see a RIGHT OUTER JOIN, my first thought is, “the rest of this review will probably be harder than it needs to be.” I find that it makes queries harder to read, because most people naturally read queries left-to-right. With a left join, the “important” table is on the left, and the query is saying, “give me everything from this table, and maybe something from this related table.” With a right join, I have to mentally flip things around to understand which table is important.

Aaron is absolutely right about left-handed scissors. I extend this as well to can openers and a half-dozen other tools that fit very well in the right hand but are quite awkward for southpaws. And don’t get me started on writing.

Aaron is kinder toward RIGHT OUTER JOIN than I am. I’m not convinced there’s ever a reason that we should use RIGHT OUTER JOIN. LEFT OUTER JOIN is much easier for humans to interpret, and (save for very specific scenarios) we should optimize code for human interpretability over pretty much anything else. And yes, that includes (again, save for very specific scenarios) performance.

Leave a Comment

Going Non-Clustered Index-Mad

Jeff Mlakar is saying the number of NCIs is too darn high!:

I wish I could say I was exaggerating when I say that I’ve investigated query performance involving 20+ NCI on a single table on more than a few occasions. “Why not?” you may think – the more NCI the better, right? Well think on this:

Click through for the reasoning. You know it’s extra-bad when 95% of those indexes have “dta” in the name. Jeff even calls that out in the post.

Leave a Comment

Copy-Pasta’d Temp Tables and More Fun

Andy Levy shares some thoughts:

I’ve spent a lot of time over the past 8 or years trying to “right the ship.” Systems that have been built and evolved over 10-15 years and the cracks are starting to show. Yes, there’s always the hot spot code that desperately needs attention, the stored procedure that runs in 6 hours but could be 20 minutes with the right adjustments. But I’m looking at a macro level today, more “operational” than “surgical.” When I see __ in a chunk of code, it’s a signal to me that there are overarching problems in how the whole system I’m working on was built and it’s going to take me a good, long while to undo that to deliver constant performance as data grows or improve maintainability.

Andy’s main topic is pre-populated temp tables serving as lookup tables in queries. Though if Andy wants eldrich temp table horrors, I raise him global temp tables (##table) created from a separate session and a SQL Agent job that runs every minute to create it, with people ignoring the failures because “That’s how it’s supposed to work.”

I’ve never seen that in practice, but now I kind of want to do it.

Bonus comment: leading semi-colons for CTEs. I rarely do that, but when I do, it’s because a semi-colon on the same line as a batch separator doesn’t count. In other words,

GO;

WITH records as (...)

returns an error. There might be some workable variant, admittedly, but in those cases, I do put the semi-colon in front of the CTE. The rest of the time, when I know there isn’t a batch separator right before the common table expression, I of course don’t. Commas and semi-colons belong at the end, not the beginning.

Leave a Comment

Impacts of Disabling Ghost Cleanup in SQL Server

Martyn Jones performs an experiment:

The first blog post introduced the ghost cleanup process, why it exists and how it works. The second demonstrated the process in action, including monitoring with Extended Events.

This post explores the ghost cleanup process further, including how it can be disabled and a high-level view of the potential impact. It also dives into data pages to show how ghost records are marked.

Disabling the ghost cleanup process can help expose internal behaviour more clearly, making it easier to observe how ghost records are marked and retained on pages.

Read on for the trace flag that can do it, as well as the consequences of doing it.

Leave a Comment

Bad Query Pattern: Wildcards on Both Ends

Chad Callihan covers this month’s T-SQL Tuesday topic:

A lot of SQL queries or code can still “work,” but that doesn’t mean it’s good, especially with so much vibe coding and the like going on these days. When I think of signs I’ve noticed when seeing a query for the first time, one thing that will get my attention (besides seeing NOLOCK throughout) is when a string is being searched for surrounded by percent signs.

I’ve had instances of working with someone that was looking for certain error logs. We may know the log record starts with “Error 123” and could search a field for “Error 123%” in our query.

Click through for the consequences of a search on “Error 123%” versus “%Error 123%”. Sometimes it’s simply necessary to do the full search, but if you find yourself doing that frequently, it’s a sign that you could design the table better.

Leave a Comment

Detecting Schema and Data Drift via SSDT

Andy Brownsword goes back to SQL Server Data Tools:

Schema drift is an inevitable part of environments where database changes are applied manually. Sometimes it’s dev-ing in production, other times it’s lax change control. Either way you’ve got a problem, and SSDT comparisons may be the solution.

In this post I want to look at how using the Schema Compare and Data Compare features of SSDT can compare different environments to detect movements in schema and core data. The key points are consistency and specificity

The engine that the Visual Studio extension uses for schema and data comparisons is pretty solid, though my recollection was that it was difficult to script these comparisons or make them work across a number of databases that should be equivalent. Back in the day, we ended up purchasing Redgate tooling for that reason, because it had an API for its schema and data comparison features. But if you’re doing a one-off comparison, the free version built into Visual Studio is pretty good.

Leave a Comment

Index Rebuild Completion Percentages in SQL Server

Andrea Allred goes searching for the truth:

I truly don’t know when it happened, but over the last while I have noticed that the percentage complete on indexes has disappeared when I run sp_whoisactive. It makes me so sad! I used that functionality often to track how things were progressing in my databases. At first I thought it was a version thing and it would come back, then I wondered if it was only when I use “ONLINE = ON”, but I am seeing it blank more and more. It has left me feeling like I am missing something and today, I finally did the digging to learn how to get that visibility back.

Click through to see how.

Leave a Comment

Settings and Configurations to Avoid in SQL Server

Jeff Iannucci has a list:

SQL Server has quite a few instance and database configuration options, which is great if you need to make changes for different business workloads. But some of these configurations can do more harm than good, especially with modern version of the product.

As a consultant, I’ve had the opportunity to work with many clients who have a diverse range of configurations for their instances. And every now and then I see some that have been configured for what I can only presume is a predilection for danger. I mean, little to no good can come of them.

So today I wanted to share with you a few that I have seen used or changed, and to recommend to you with all the influence that I may have, that you DON’T TOUCH THEM – THEY’RE EVIL!

The contrarian in me wants to poke holes at some of these, though all of his database-level settings are defensible. On the instance level, I do have some gripes, specifically with fill factor (at least if you’re following Jeff Moden’s strategy). I thought about having a gripe around min server memory, but that’s reasonable—it’s max server memory that tends to be much more important to change.

Leave a Comment

What Comes Next for SQL Server 2016

Debbi Lyons lays it out:

As of today, July 14, 2026, SQL Server 2016 has reached end of support.

For the past decade, SQL Server 2016 has helped organizations run mission-critical applications and support the data needs of their business. Whether it was end-to-end encryption with Always Encrypted or performance improvements with In-Memory OLTP, SQL Server 2016 was shaped by evolving data platform needs and what we heard directly from customers like you.

Last year, we shared guidance on how to prepare for this milestone: Protect and modernize SQL Server 2016 workloads with Microsoft. Now, after 10 years of powering innovation, the focus shifts to what comes next.

It basically comes down to “Pay Microsoft a lot more money for one-off security fixes or upgrade to a version that isn’t a decade old.”

Leave a Comment