Press "Enter" to skip to content

Curated SQL Posts

Ways to Impute Missing Data in R

The DataScience+ desk compares methods:

Missing data is the daily reality of medical and epidemiological work: a patient skips a lab draw, a questionnaire item is left blank. So in this tutorial I use real health-survey data and compare three current imputation packages on it: mice (multiple imputation, still the reference method for statistical inference), missRanger (random-forest imputation, the fast successor of missForest), and VIM (k-nearest-neighbour imputation). Before any imputing I use naniar, the modern, ggplot-native toolkit for missing data, to picture where the gaps are. I also include the method most analyses actually use by default, dropping incomplete rows, because seeing why it fails is half the point.

I start from complete records, delete values myself, and check each package against the truth I hid.

Click through for the method and different ways to impute data to fill in the gaps. The text of the article looks AI-generated, though the recommendations end up being pretty solid (at least in my experience with imputation and working with mice).

Leave a Comment

Page Splits in Animated Form

Brent Ozar paints a picture:

You’ve heard that page splits are bad, and they’re an indication that your table design is making your storage work too hard. You’ve heard that the right answer to fix it is adjusting fill factor lower, or doing regular index maintenance.

Before you watch the below animation, you’ll wanna get up to speed with how index seeks work. Then, let’s explain page splits with an animation:

Click through for the visual explanation.

Leave a Comment

Working with DATEDIFF() and DATETRUNC()

Erik Darling has a video for us:

So we’re going to talk about just some not terribly advanced stuff, but stuff that is at least worth making sure that everyone understands when it comes to the date diff function.

There’s not terribly a lot of advanced things to say about it, but who knows where you’re starting off. So one thing that seems to get on some people’s nerves is deciding on a boundary.

So when you say, I only care about a year of data, you need to think carefully about how you do that. 

This is one tiny part of how working with dates is so painful, and not specifically due to any gap in tooling but just in how complex date and time logic is. And that’s before we even think about the date math involved in working with the Future Semiconditionally Modified Subinverted Plagal Past Subjunctive Intentional.

Leave a Comment

Exfiltrating Data via sp_invoke_external_rest_endpoint

Vlad Druma slides some data past the bouncer:

In this post I cover how an attacker can take advantage of SQL Server 2025’s sp_invoke_external_rest_endpoint to exfiltrate data from a compromised instance.

In my previous post I used sp_invoke_external_rest_endpoint to get some data about internet-exposed SQL Server instances.
While doing that, I realized that, similarly to xp_cmdshell, SQL Server 2025’s sp_invoke_external_rest_endpoint can be used by an attacker to exfiltrate data from SQL Server.

Click through to see how.

Leave a Comment

Solving the Jug Problem with Bezout’s Identity

Tomaz Kastrun shifts liquids:

With DFS we can solve this with Bezout’s identity; which in general is a theorem which relates two arbitraty integers with their greatests common divisor; and used in algebraic language, finding common zeros of n-polznomials in n-indeterminates. So the common zeros equals the product of the degrees of the polynomials.

The idea, to refresh your memory, is that you have three jugs of different sizes. Tomaz uses 16L, 11L, and 7L. Using just those, how can you get 8L into each of the two larger jugs? Click through for the answer.

Leave a Comment

Securing SQL Server Maintenance Tasks

Fabiano Amorim shares some advice:

SQL Server is often marketed or perceived as secure by default, but real-world testing shows that default installations and default permissions still expose several attack surfaces. With this in mind, “secure by default” does not mean “safe without review.” 

Many risks come from legacy behavior, backward compatibility, broad permissions granted to the public role, system procedures, implicit trust boundaries, and administrative convenience features. 

The risk appears when they are combined: a database user with more permissions than necessary, a maintenance job running as a highly privileged owner, an unexpected trigger, or an impersonated module that changes how permissions are evaluated. 

Click through for a depiction of how the attack path works and things you can do to prevent systems compromise.

Leave a Comment

Thoughts on Fabric User Data Functions

Jon Lunn shares some thoughts:

Fabric User Data Functions are a bit of a strange hybrid. They can be used like Azure Functions, to call some code outside and act like a serverless compute function, but also can extend notebooks as a source of reusable data logic. I’ve been using them since preview, and now they support Azure Key Vault (AKV) and Fabric Variable Libraries, I think they are ready (mostly) for productionable use.

I think the part that annoys me the most about them is that they’re called “User Data Functions” instead of “User-Defined Functions” and yet the acronym is the same.

Leave a Comment

MSDB 110_upgrade.sql Failed with Error 574

Jordan Boich troubleshoots an issue:

SQL Server won’t start and at first, I couldn’t figure out why. When I logged off for the day on Friday, everything was happy, but when I logged on Monday morning, a heavily used test instance of SQL was not running and wouldn’t start.

Quick side note, and it’s funny looking back on now, but in the moment it sucks. You ever have to start the SQL Server Service from Configuration Manager, and when you right click -> Start, or right click -> Restart you see that green progress bar start to go and under normal healthy circumstances, it probably gets a third of the way through before SQL kicks over. But when you start to see that progress bar start to make more and more progress, you know before it even fails on you that something isn’t going to work right. You start to get that sinking feeling in your stomach. That was me.

Click through for the troubleshooting process as well as the end result.

Leave a Comment

Shrinking Power BI Datasets via Parameter Filtering

Andy Brownsword’s appeal is becoming more selective:

When developing Power BI models, we don’t always want to refresh the entire dataset before we start working with the data. We can speed up the refresh – and therefore our development – by reducing the volume we’re working with.

Here we’ll look at a couple of ways to use parameters to adapt production-ready models to reduce and tailor data volumes for development.

Click through to see how.

Leave a Comment