Press "Enter" to skip to content

Curated SQL Posts

A Primer on Contained Availability Groups

Dualcore DBA tries out contained Availability Groups:

Contained Availability Groups look to solve a long-standing issue in SQL Server HA/DR solutions, which is that most of them (Mirroring / Log Shipping / Availability Groups) work at the database level but there can be and often are server-level objects on which that database depends. Classic examples of such server-level dependencies are (but not limited to) logins and agent jobs. These server-level objects need to exist on all the HA/DR nodes as well as requiring careful management (matching SIDs and passwords for logins) and careful configuration (agent jobs that only run when the node is primary etc).

In the case of SQL Server logins, these exist in the master database, which is responsible for all server-level configuration and metadata. In the case of agent jobs, these are stored in the msdb system database, which is responsible for everything SQL Server Agent related (as well as storing backup history, database mail configuration etc). As both of these system databases do not get replicated in HADR scenarios, there is the need for manual synchronisation of objects.

Both instances we will work with in this demo are on SQL Server 2022 Developer Edition and so benefit from Enterprise Edition features. Contained Availability Groups are an Enterprise Edition feature.

Click through for the demo on how to set one up and where you might run into trouble.

Leave a Comment

Finding the Real tempdb Culprit

Aaron Bertrand is searching all of the golf courses:

In my previous post, I described a monitoring system that tries to get ahead of tempdb capacity problems instead of waiting for a full disk alarm to tell us something went wrong. It collects lightweight snapshots continuously, captures more detailed information when space starts getting tight, and can even disconnect particularly troublesome sessions when the right conditions are met.

That’s all useful for dealing with an incident while it’s happening. But one of the main reasons I built this system was to help with the inevitable question that comes afterward: What caused it?

We now have historical snapshots, session and request details, log transactions, growth events, and an audit trail of sessions nominated for termination (and the outcome of any attempts to terminate them). That’s a lot more information than I’d have trying to reconstruct an incident from DMVs after everyone has disconnected and gone home.

Unfortunately, having all this data doesn’t automatically make it easy to find the answer. 

Read on to learn what Aaron does to find an answer.

Leave a Comment

The Fibonacci Sequence and Factorials in T-SQL

Tomaz Kastrun has a new series running this month, and it’s all about mathematical operations in T-SQL. Day 1 kicks us off with the Fibonnaci sequence:

T-SQL is funny solving fibonacci sequence. It has been done so many times, that it is nothing new. Problems are two-fold. The bigint will be maxed out by 91st number and recursions must be controlled.

So in this case, I have put MAXRECURSION to a given number of 150, yet I am controlling the “n” within the CTE.

Day 2 covers factorial numbers:

T-SQL is funny solving factorial numbers. As it exists in scripting and programming languages, there is still none available in T-SQL. The closes is a PRODUCT() function, but it is not factorial out-of-the-box. Similar to Fibonacci, Factorial also has similar problems The bigint will be maxed very fast, so using DECIMAL(38) will get you yo 34!

Click through for versions of the factorial query that work for SQL Server 2025 and for prior versions that did not have PRODUCT().

Leave a Comment

Microsoft Fabric OneLake Storage Tiering

Koen Verbeeck saves some money:

We are building a large data platform using Microsoft Fabric. We have a bunch of lakehouses where unstructured data – such as raw files, images, video, logs etc. – are stored, and the total storage already goes into the terabytes. Is there a way we can optimize our storage costs? For example, in Azure Blob Storage there are different storage tiers. Does OneLake have this option as well.

Read on for the answer, as well as some of the issues you might run into if you do change storage tiers for blob storage accounts in your workspace.

Leave a Comment

What Was New for T-SQL Developers in SQL Server 2017

Jeff Taylor has a (short) list:

How many of us still type LTRIM(RTRIM()) today? You don’t have to anymore. SQL Server 2017 finally fixed that, along with a few other string headaches. This is part 3 of my “What’s New in SQL Server for the Developer” series, based on my session. So far we’ve covered 2012 and 2016. Today it’s 2017.

And, in addition to simplifying the LTRIM(RTRIM()) pattern, TRIM() also allows you to trim non-space leading & trailing characters, as Jeff shows.

Leave a Comment

Ingesting On-Premises Data into Microsoft Fabric via Notebooks

Nikola Ilic shows off a solution:

For most of Fabric’s life (and it’s been more than 3 years now), the answer to “can my Fabric notebook read our on-premises SQL Server?” was… Eehhmm, no… The on-premises data gateway worked for pipelines, Dataflow Gen2, and mirroring, but not for notebooks. The standard workaround was to ingest the data with a pipeline first, and only then pick it up in Spark. In February 2026, the Execute Query REST API opened a side door: a notebook could call it to run Power Query M inside a Dataflow Gen2 item (gateway included), as long as the query finished within 90 seconds.

The November Fabric feature summary turned that into a native notebook feature. A new module, notebookutils.powerquery, runs Power Query M from a notebook through an existing Fabric connection, including a gateway-backed one! The result comes back as a PySpark DataFrame.

But read on for the limitations in this solution.

Leave a Comment

Fixing a PAGELATCH_UP Issue in SQL Server

Anna Hoffman reviews a paper:

This is a really interesting type of engineering paper. No new architecture, no new theory. Just a team looking hard at a bottleneck everyone had accepted for twenty years, and removing it.

The bottleneck was a single byte. Yes, really.

Concurrent Updates to Pages with Fixed-Size Rows Using Lock-Free Algorithms (VLDB 2020) is about how SQL Server keeps track of free space, and how fixing one small piece of that produced up to 5x throughput on some workloads.

Read on for Anna’s synopsis and an example of where it could help. This is built into SQL Server 2019 and later, so there’s nothing special to do, other than to be on a version of SQL Server released in the last eight years.

Leave a Comment