memory occupancy for NULL

  • This would not be a greate question. but really i could n't understand this?

    How much memory does NULL occupies. is it depends on datatype pf the field?

    or does NULL have any fixed memory size?

    or  NULL doen't occupies memory?

    as far as mt Knowledge NULL does n't occupies memory when it is in the last field. But what if they in the middle?

     

    Any one please clarify...

     

    Thanks in adsvace

  • You should read the following topic from Books Online :

    http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_02_2248.asp

    My understanding of this topic is that the storage of null values highly depends on whether the column is fixed-length or variable-length and also of the number of other null-able, fixed-length columns in the table. Anyway, a NULL value will not occupy space per se, but SQL Server has to use a "null bitmap" if there are fixed-length, null-able columns. In this case we could say that each fixed-length, null-able column will take one bit (1/8 of a byte), whether the actual value is null or not. In the case of variable-length columns the null-ability of a column will not cause any overhead, because it is stored in the same 2 bytes that are used for the size of the data.

    Razvan

  • Depends on what you mean by memory however. The previous person hits on the aspect of the data on the file and in the row itself in memory which pretty much stays in foot with if data is in all the columns instead of null except for variable length columns which only list there 2 byte offset when they are occupied or a data element in the row occupies a point past a nulled column.

    As for memory it is a presentation thing and NULL takes approximately 4 bytes (depends on the application and display method) to display the word NULL as opposed to '' but '' is not the same as NULL nor is 'NULL' the same as NULL even thou they both use 4 bytes per occurrance. Every character displayed always take the amount of memory it takes to so a character.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply