Sunday, December 14, 2008

Char column contains a lot of NULLs. Should change to varchar?

Most of the time, the decision of the usage of data types, char or varchar is depending on, whether the values are fixed-length or variable-length. Varchar is used when the length is vary and number of characters expected are greater than 10 (heard about this before? ). There is another fact to be considered which most ignore which is nullability of the column. What if the type is char and it is fixed-length, and contains a lot of NULLs. We cannot forget that char takes up the assigned number of bytes even it contains NULL. Therefore, considering this factor, if your char column contains lot of NULLs, you should really think of changing it to varchar data type.

No comments: