Friday, March 9, 2012

NULLs

Do NULLs take up space on the Database? I mean is room allocated for them?so using NULLs also saves space - right?|||I thought it depended on the datatype. Like Char(500) still allocates 500 spots. Null just means those spots aren't taken by anything yet. I think the case is the same for Binary types also.

I could be wrong on this one though. Just wanted a little clarification on the matter other than "no".|||no, there is no allocation for nulls.|||So what you are saying is that varchar and char are basically the same? I mean if I declare char(50) only use the first ten and fill the rest with NULLs - it is the same as varchar(50).|||no, nulls are the same

char(50) is the actual string + spaces (the whole length is 50)
it has nothing to do with what we are talking about here|||If I wrote "abc" in field of type Varchar(50) actually I will store only 3 spaces ,, but if I use char(50) field I will reserve all of the spaces , otherwise I think SQL Server do its best to optimize storage.|||If a variable length field contains a NULL value, it will take up no room in the data row. SQL Server has a data structure known as a 'NULL bitmap' on each record, the NULL bitmap will be long enough to have 1 bit for every column in a row ( 5 columns could be covered by 1 byte - 8 bits). If the bit is set for a column, SQL knows the column value is NULL.

Fixed length columns always use the full number of bytes, even if the record contains NULL for the column. (This wasn't so in SQL 6.5, though).|||I'm with bitmask on this one. mcdba or not, fix length columns always use the full number of bytes and allocate a specific amount of memory regardless of the value being null or not.

No comments:

Post a Comment