Press "Enter" to skip to content

Curated SQL Posts

For the Love of Markdown

Louis Davidson explains an opinion:

I had no idea what the three tick marks “` meant until soon after I left there because all my recent experience had been with use the Mammoth Word Document converter. It works pretty nice overall, but it had been something I had struggled with over the years trying to get other people’s documents into to work just right. (Ok, and my documents too.)

It worked by mapping styles in a Word Document to a style in a WordPress page. To do it well, I had my template with all the styles set up in the Word template with shortcut keys, which I used an Elgato Stream Deck to remember all the keys. I still use a stream deck for editing, which I will share about some day.

So when I started my own site, I tried hard to replicate that experience but better. Until recently, you couldn’t support plugins in WordPress without spending quite a bit more money than I was willing to spend on this site so I started trying to find the best way to work offline and then (more or less) paste in my text.

Click through for a bit of Louis’s journey. Also, Louis mentions being confused by the name and thinking it was “markup.” That’s because HTML is the Hypertext Markup Language, and John Gruber meant the name as a pun on heavier markup languages like HTML and XML, as Markdown involves much less marking up of the text.

Comments closed

Having Fun with the SQL Server Debugger

Brent Ozar hits us with a blast from the past:

And you’ve wondered what the big deal is. Well, kiddo, in this post, let’s take a trip down memory lane and I’ll show you how good we used to have it.

First off, you’re gonna ask why the debugger console display isn’t on. Buckle up, because this is a journey.

Long before we could run the debugger and Profiler remotely, and certainly a long time before the days of USB, we had to attach the debugger directly to the SQL Server we needed to monitor. To do it, we used to have PS/2 ports on the backs of our computers (there were other ports before that, and yes i remember them, and no, I don’t even wanna think about how bad debugging was back then.) The debugger console plugged into these ports:

By the way, as Brent’s tag points out, this was a joke. Though that does look like a neat editing controller.

Comments closed

An After-Action Report of a DR Scenario

Jordan Boich tells it like it is:

As anyone in IT will tell you, when an outage strikes, and all hands are on deck, that is something that will wake you up faster than any cup of coffee. That was me. Waking up trying to get my bearings to take part in addressing an outage with my bed-head in full effect (Thank you Microsoft Teams for giving that little preview window to show what you look like before you turn on your camera).

Click through for the full story.

Comments closed

Replacing REPLACE()s with TRANSLATE() in SQL Server

Greg Low makes use of an uncommon function:

If your T-SQL is buried under layers of nested REPLACE() calls just to swap out a few characters, there’s a simpler way. SQL Server’s TRANSLATE() function — introduced in 2017 but still rarely used — lets you replace multiple characters in a single string with one function call instead of stacking several REPLACE() functions inside each other.

This guide covers how TRANSLATE() works, how it compares to REPLACE(), and where it falls short compared to other SQL dialects like PostgreSQL and Oracle.

One important thing to remember with TRANSLATE() is that it’s a character-for-character replacement. In other words, if you TRANSLATE('ABCDEFG', 'x'), it will replace every instance of each of those characters with the letter “x.” It doesn’t replace a substring.

Comments closed

Scripting SQL Agent Job Creation Scripts

Aaron Bertrand sees that it’s all funhouse mirrors:

On this site, we usually talk about SQL Server performance problems that involve execution plans, locking, indexes, and waits. But SQL Server Agent can determine when backups, maintenance, ETL, monitoring, and reporting all arrive at the instance. In a way, a job deployment script is part of your performance configuration: you can materially impact the workload if you accidentally share a schedule across too many jobs.

I often create jobs in test environments that will later get distributed to many servers, often in isolated environments that can’t see each other. Creating an idempotent script to create a job, but only if it doesn’t already exist, can be cumbersome to get right. Many will prefer to use DbaTools Copy-DbaAgentJob, and that can be a great option if your deployment mechanism is PowerShell, DbaTools is already entrenched in your environment, and you can run the script from a place that can see the other server. In our case, T-SQL scripts are often passed on to colleagues or automation to be run independently in a different environment. Apologies to friends of SSMS, but the default right-click > Script Job output leaves a lot to be desired:

Click through for a variety of problems that the scripting logic has, as well as the solution Aaron came up with.

Comments closed

The Importance of Disaster Recovery Testing

Vlad Drumea performs some tests:

After the ANCPI hack that took down Romania’s land registry, Andrei Avădănei, CEO of Bit Sentinel and founder of DefCamp, published on LinkedIn a detailed proposal for a national offensive security program.
It covered pentesting frameworks, vulnerability disclosure, continuous monitoring, and accountability measures. The proposal was thorough, logical, and exclusively focused on prevention and detection.

I left a comment suggesting one addition: mandatory disaster recovery simulations.
Can institution X recover after their entire production environment is encrypted? If so, how long does it take and what data is lost? Are there backups? And if yes, are they actually viable, or are they Schrödinger’s backups, where you only find out whether they work at the exact moment you need them?

This exchange made me realize that organizations, especially in the public sector, rarely consider doing disaster recovery tests.

I’ve been on the edges of DR scenarios at prior jobs, including one at a state agency. Most of the time, the tests have to be hypothetical or piecemeal because we rarely had the hardware to support a full switch-over, or the budget to spin up an equivalent set of hardware in a different region.

Comments closed

Taking Advantage of Newer Date Functions in SQL Server

Andy Brownsword gets beyond SQL Server 2000:

Date handling in SQL Server tends to accumulate tried and trusted combinations of DATEPART()DATEADD(), and DATEDIFF() – with nested variations. The challenge with these isn’t raw performance, but more with conveying intent and readability.

So let’s look at some simpler patterns to try and avoid some of these and be clearer with what we’re trying to achieve.

Click through for some functions that have been around since 2012, and others that just became available in 2022.

Comments closed

The Perfect Trick to Speed Up Databases

Louis Davidson becomes a cracker jack developer:

This week, I want to sell you on two ideas. First, that you can make any query faster with:

  • Zero hardware changes
  • Zero index changes
  • Zero structure
  • Just a few simple character changes in every one of your queries

This change I will guarantee will make your queries screamingly faster. Never will your customer’s wait on query results again. You will have no blocking, no latch waits, no waiting whatsoever.

He probably should sell this as a training course, along with its administrator equivalent: databases hate date, and you can’t have data problems if you don’t have any data.

Comments closed

Displaying Detail Rows Expression Results in Power BI

Chris Webb works around a limitation:

In last week’s post I mentioned that while Power BI reports (unlike Excel PivotTables) do not support the Detail Rows Expression feature, it is possible to partially work around this limitation by using the paginated report visual. In this post I’ll show you how I was able to do this and what is and isn’t possible.

Click through to see how. I’m unclear as to whether this also applies to Power BI Report Server, though my default expectation is “No, it does not apply, because nothing new ever applies for Power BI Report Server, because Power BI Report Server users don’t deserve nice things.” But that’s just because of years of experience in not having nice things with PBIRS, not any specific information.

Comments closed