The Bit Bucket

DevOps: Microsoft Professional Program for DevOps

In the second half of 2016, I enrolled in the Microsoft Professional Program for Data Science, and completed it in early 2017. I have to say that I really enjoyed it overall. It was a bit challenging at times but I don’t regret doing it.

If you want to get the certification, you need to enroll in the verified option for each course. Nowadays, that’s pretty much $99 USD per course. You can do it for free, and if you’re tight on funds, perhaps that’s what you should do. I like to support the concept, and like to support both Microsoft and edX for creating these options. They are doing amazing work, so while I hear people say to just do the courses and not contribute to them, I can’t say that I agree.

2018-01-05

Shortcut: Creating T-SQL Templates in SQL Server Management Studio (SSMS)

A few weeks back, I mentioned how useful templates can be. I said that I’d discuss how to create them later. Well that’s today.

I thought I’d take dropping a database as an example. The supplied template doesn’t work for me, so let’s create a new one.

Note: SQL Server 2016 SP1 introduced DROP DATABASE IF EXISTS but I find that option quite useless. It fails if anyone is connected to the database. And to disconnect people beforehand, you need to first check if it exists, so the statement is pointless.

2018-01-04

SDU Tools: Determining Leap Years in T-SQL with IsLeapYear

Is 2018 be a leap year?

Was 2000 a leap year?

Will 2100 be a leap year?

When I was a young student at school, we learned that leap years were every four years. Then as I got older, I learned that there was more to it than that.

It’s important to understand that any calendar is just an approximation, and there is a lot more to calendars than most people realize.

2018-01-03

SQL: Auto Page Repair in SQL Server ? (Or Not?)

Database mirroring was added in SQL Server 2005. One of the features added to it in SQL Server 2008 was auto page repair. When SQL Server 2012 was released, Availability Groups also offered auto page repair.

Just how useful is this feature though?

I’ll start by saying that it can’t hurt.

When SQL Server is reading a page on the primary replica and receives an unrecoverable I/O error (typically but not always, an error 823 for a checksum error), it will try to repair the page when:

2018-01-02

Opinion: If you can't type, you are writing worse code than if you could

Let me make a potentially bold statement:

People who can’t type write worse code than they could be writing

I’m sure that will upset some people (probably those who can’t type or who are two or four finger typists) but it’s a conclusion that I’ve come to over many years. Coding is clearly not the same thing as typing but the reason is simple:

To write good code, you need to be prepared to constantly refactor and rework the code that you write, and if you can’t do that quickly, you’ll be more reluctant to do it.

2018-01-01

SDU Tools: Converting T-SQL Strings to Snake Case and Kebab Case

In a recent blog post, I described converting strings to Proper Case and Title Case. And more recently, I described how to convert them to Pascal Case and Camel Case.

The final option (for now) in this set is conversion to Snake Case and Kebab Case.

In Snake Case, all words are lower-cased, then all spaces between words are replaced by underscores.

You can see it in this example:

2017-12-29

Shortcut: Using Colors to Avoid Running Scripts Against the Wrong Server

Everyone who’s worked with SQL Server for any length of time, has had the experience of executing a T-SQL script, and then noticing, with horror, that they’ve just executed the script against the wrong server.

You know the feeling. It even happens at Christmas time, just when you were hoping to get away from work for a few days, or when you are the unlucky one who’s doing on call work.

2017-12-28

SDU Tools: Show SQL Server Backup Completion Estimates

When you first start working with SQL Server, you’re often working with smaller databases and every backup seems to happen quickly. SQL Server is fast at creating backups.

When you get to larger databases, backups start to take a while. Fortunately, backup is one of the commands that sets a percentage complete value that can be seen in the sys.dm_exec_requests system view.

And when the databases get even larger, the question quickly becomes:

2017-12-27

Opinion: And One Column to Rule Them All

I work with a lot of SQL Server databases that are poorly normalized. One of my pet dislikes is the column to rule them all.

Here are simple tests:

If I ask you what’s stored in a column and you can’t tell me a single answer , then you’ve got a problem.

If you need to refer to another column to work out what’s in the first column, then you’ve got a problem.

2017-12-26

SDU Tools: LeftPad and RightPad in T-SQL (Right-align, Left-align)

Over the years, I’ve had a surprising number of questions on how to right-align a set of numbers using T-SQL.

The first concept that people seem to miss is that numbers aren’t strings. So there’s no concept of actually aligning a number, it’s only a string representation of a number that can be right-aligned or left-aligned. Or how it’s displayed in a client application.

But if you really want to create a string that has right-aligned numbers, then left padding of the number is what you want.

2017-12-22