1

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
  • 1
    This answers your question
    – Nelson
    Feb 25, 2015 at 11:53

1 Answer 1

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.