I am using a SQL Server database. If NULL
value is inserted to a VARCHAR
datatype column, what will be the memory size used for the column?
1 Answer
Each variable-width column in a row will require a single bit to maintain the nullability status (this is so SQL Server can check this bit, rather than skipping down to the row and parsing the contents of that column). Of course you can't add a single bit to a row, you need to add a byte for this data, which means that if you have a single variable-width column, there is a byte of overhead, and that byte can be used to store the nullable status of up to 8 columns (I haven't tested if there are row configurations where multiple but < 8 variable-width columns may still use different nullable bytes).
Note: there is other overhead for variable-width columns, such as length, but I believe in general that that overhead is the same whether the column is nullable or not.