messy paint cans and colours

How SQL Server stores data types: sql_variant

This post looks at a curious data type that isn’t really a data type. Instead, sql_variant tries to be all things to all people. As with most things in life, it has a few shortcomings as a result. If you would like to read about storage of other data types, here are the previous posts
-> Continue reading How SQL Server stores data types: sql_variant

A half-closed MacBook

How SQL Server stores data types: XML

This week we’re looking at how the database engine stores the XML data type in SQL Server and Azure SQL Database. If you would like to read about storage of other data types, here are the previous posts in the series: Bit columns Dates and times Integers and decimals Money Floating points GUIDs What is XML?
-> Continue reading How SQL Server stores data types: XML

A wall of scattered pages from a book

The final word on storage for DATETIME2

Two years ago I wrote a post that got a lot of traction in the comments at the time. Last month there was renewed interest because one of the commenters noted that the official SQL Server documentation for DATETIME2 disagreed with my assertions, and that I was under-representing the storage requirements. To remind you, I
-> Continue reading The final word on storage for DATETIME2

Colourful book case with paper files

Canada Day 2020

It’s Canada Day here, the commemoration of the country’s confederation in 1867. Given events over the last few months such as the worldwide pandemic, followed by a number of politically-motivated movements for change across the United States of America and other countries, it’s a good idea to reflect on what database design might look like
-> Continue reading Canada Day 2020

Assorted coin lot in clear glass jar

How should I store currency values in SQL Server?

On Twitter, Michael Dyrynda writes: ⚠️ Never ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever ever store currency as
-> Continue reading How should I store currency values in SQL Server?

A stack of coins

How SQL Server stores data types: money

In this post we look at how SQL Server stores currency values using the MONEY and SMALLMONEY data types. If you’d like to read the previous posts in this series of how SQL Server stores data types, here’s what we’ve got so far: Bit columns Dates and times Integers and decimals 🎶 It’s a rich
-> Continue reading How SQL Server stores data types: money

Blue number notebook

How SQL Server stores data types: integers and decimals

This week we’re going to look at how numbers are stored. This post will cover integers (TINYINT, SMALLINT, INT, BIGINT), and decimals (DECIMAL, which is the same as NUMERIC). If you’d like to read the previous posts in this series of how SQL Server stores data types, here’s what we’ve covered: Bit columns Dates and
-> Continue reading How SQL Server stores data types: integers and decimals

Calculator on written page

Negative identity values don’t suck

A quick(er) post this week, in response to Greg Low’s blog post from a few weeks ago titled “Don’t start identity columns or sequences with large negative values.” Greg writes that you shouldn’t use large negative values in a table, because… it’s hard to read them, I guess? And also they don’t compress well. I
-> Continue reading Negative identity values don’t suck

flat lay photography of purple and red leaves

The XML data type is not immutable

Immutability In many programming languages, strings of text are immutable, meaning they don’t change. When you modify a string, a new string is created in memory by copying the original. The old string stays in memory unless some process removes it. This might be a manual process of de-allocating that memory, or garbage collection if
-> Continue reading The XML data type is not immutable

The easy way to handle UTF-8 in a .NET application when dealing with SQL Server 2019

A short post this week. On a mailing list recently, someone noticed that a .NET application writing to SQL Server did not have the expected behaviour with UTF-8 collation and data types. To refresh our memories, UTF-8 is newly supported in SQL Server 2019, and provides potential savings of up to 50% when storing strings,
-> Continue reading The easy way to handle UTF-8 in a .NET application when dealing with SQL Server 2019