patternModerate
Do empty columns take up space in a table?
Viewed 0 times
spacecolumnstakeemptytable
Problem
I have table that holds from very basic info. Just a title and a few date fields.
There's one field called comments which is varchar(4000)
Most of the time we leave it blank, but some times will enter a large amount of data here.
Is this a really bad design? Or is this just slightly inefficient?
I would assume the creating a separate table for this column would be better.
note: this is sql server 2008
There's one field called comments which is varchar(4000)
Most of the time we leave it blank, but some times will enter a large amount of data here.
Is this a really bad design? Or is this just slightly inefficient?
I would assume the creating a separate table for this column would be better.
note: this is sql server 2008
Solution
It takes minimal space when not used
The overhead is minimal and optimisation will be premature.
Until you know you have an issue, just keep it in one table. You break KISS by introducing outer joins and add an overhead in querying the data.
See https://stackoverflow.com/questions/3793022/how-to-come-to-limits-of-8060-bytes-per-row-and-8000-per-varchar-nvarchar-valu/3793265#3793265 for more
- one bit in the NULL bitmap
- two bytes for length (which will be zero when NULL)
The overhead is minimal and optimisation will be premature.
Until you know you have an issue, just keep it in one table. You break KISS by introducing outer joins and add an overhead in querying the data.
See https://stackoverflow.com/questions/3793022/how-to-come-to-limits-of-8060-bytes-per-row-and-8000-per-varchar-nvarchar-valu/3793265#3793265 for more
Context
StackExchange Database Administrators Q#11664, answer score: 13
Revisions (0)
No revisions yet.