The Bit Bucket

T-SQL 101: 16 Ordering the output of a T-SQL query

When you run a query against SQL Server, you might want the rows to be returned in a specific order. However, the first thing you should ask yourself is whether that’s needed at all.

Sorting can be a very expensive operation if there is no suitable index that’s already sorted the data for you. And the question is: should SQL Server be the one doing the sorting? In many cases, the client application that’s reading the data might be a better place to do the sorting. That’s not always true but it’s worth considering. You often have way more clients than your single database server, and sorting data unnecessarily in the database server could limit your ability to scale your system to higher volumes.

2019-05-06

DevOps: Is AIOps just yet another almost meaningless acronym?

DevOps has quickly become a core part of how many organizations deliver IT, and in particular, how they deliver applications. But just as quickly as it has become popular, a whole series of XXXOps names have appeared. One of the latest is AIOps. So is it just yet another almost meaningless acronym?

Well as Betteridges Law of Headlines suggests, the answer is no.

When I first saw the term, I was presuming this would be about how to deploy AI based systems, and I wondered why on earth that would need a special name. But that’s not what it is.

2019-05-03

Fixing Locking and Blocking Issues in SQL Server - Part 3 - Indexing

This is part 3 in a series of posts:

  • Part 1 covered being sure there is a locking and blocking issue
  • Part 2 covered the impact of RCSI

Today, though, I want to look at the next potential issue, and that’s indexing.

Indexing impacts on locking

It might seem obvious that you need to fix indexing issues in your database applications but it mightn’t be so obvious that locking is one of the main things that is affected.

2019-05-02

SDU Tools: Retrust Foreign Keys and Check Constraints in SQL Server

While doing my consulting work, I often come across Foreign Keys and Check Constraints that are not trusted. What this means is that either:

  • They were created without checking existing data
  • They were disabled for a period and re-enabled without re-checking the existing data

I like to see this fixed whenever possible. To make that easy, in our free SDU Tools for developers and DBAs, we added two stored procedures to help: RetrustForeignKeys and RetrustCheckConstraints.

2019-05-01

Book Review: The Happy Mind

Over the years, I’ve been really interested in what makes people happy in life. I’m always fascinated by people who think that wealth, products, properties, the latest handbag or car, new partner, etc. will make them happy. I’m sure the media has tried to tell them that, but it’s never been true.

I’ve had friends all colleagues all across the wealth spectrum, and I can say without any doubt in my mind, that some of the richest people I know are also some of the most unhappy. Worse, I’ve seen money destroy families so many times.

2019-04-30

T-SQL 101: 15 Using column and table aliases in SQL Server queries

Look carefully at the following queries:

I’ve shown several examples here of what are called aliases. There are two basic types of aliases.

Column Alias

In the first query, I’ve used a column alias. I wanted to query the Description column in the dbo.Products table but I wanted the column called ProductName instead. So I follow the column with the word AS and then the name I want to use for the alias.

2019-04-29

Book Review: Why we get fat and what to do about it by Gary Taubes

Weight has been an area of interest for me for a very long time, given my struggles with it. All throughout the 1980s, I wish I’d known what I do know now. Gary Taube’s book Why we get fat and what to do about it was a seminal work in this area, helping to remove the nonsense that’s been peddled as “science” and “medicine” for decades.

I was already pretty much across most of Gary’s work before I listened to this as an audiobook, but it helped me to see where much of his thinking had come from.

2019-04-26

Fixing locking and blocking issues in SQL Server - Part 2 - RCSI

This is part 2 in a series of posts:

  • Part 1 covered being sure there is a locking and blocking issue

In part 1, I talked about pseudo locking and blocking issues that come from having queries running too long. I said that before you start fixing any locking and blocking issues, that you first need to make sure your queries are running fast. Today I want to discuss RCSI.

2019-04-25

SDU Tools: Using T-SQL to find operating system versions, locales, SKUs, and configuration

When I’m writing utility scripts for SQL Server, I often need to make decisions or report on, details of the operating system that I’m running on. Unfortunately, SQL Server doesn’t have views that return this sort of information.

In our free SDU Tools for developers and DBAs, we added a series of views to help.

OperatingSystemConfiguration has details of OperatingSystemRelease, OperatingSystemName, ServicePackLevel, OperatingSystemSKU, OperatingSystemSKUName, and LanguageName.

OperatingSystemVersions has details of OS_Family, OS_Version, and OS_Name.

2019-04-24

Another new online course: Protecting SQL Server Data with Encryption

We all see news articles talking about how company after company exposed private details of their clients, customers, and sometimes, even staff. In so many cases, a reasonable approach to encryption would have avoided these issues. Time and again though, I see people doing dodgy work on protecting their data; some even trying to roll their own protection.

Don’t do this!

Encryption is one of the most important yet least understood technologies in SQL Server. It’s improved so much over the years and 2019 makes it even better.

2019-04-23