Which is better for storing empty values in SQL Server 2012 in terms of size – an empty string or null?

Testing methodology: 2 databases were created, each with a single table containing only an int column and an NVarChar(20) column. The first one always received NULL values in the NVarChar column, while the second database received empty strings. Once again, my goal here is to save as much space as possible. And the result?

The null.mdf file had 278104 rows written in 265 seconds

The EmptyString.mdf file had 535543 rows written in 584 seconds

What is the lesson to be learned from this? That it is a good idea to store null values not as null, but as empty strings, if they are of a text type such as the already mentioned NVarChar. The write speed is comparable, but the size is roughly 2x smaller.

Categories

Leave a Reply