CRAIG SHASHI ------------ CANADA ...etc
My second row is having 20 blank bytes....like this. If my table has millions of rows am I wasting a lot of space by putting each NULL row with 20 blanks? How do I avoid this? I mean how do I make it one byte (Nullable) or blank instead of 20?
Requires Free Membership to View
You might want to choose the VARCHAR data type for this column instead of the CHAR data type. This will enable you to store only the amount of bytes required for each column value - that is, 5 bytes for CRAIG, 6 bytes for SHASHI, 6 bytes for CANADA, etc. Of course, this is not 100% accurate because a variable column requires a 2 byte length indicator. So every row will always require the 2 byte length indicator, but if the column is set to null you can set the length indicator to 0 and save space. Keep in mind, though, that you will have to programmatically set the length of each column as it is inserted or updated into the table.
Using your example, to use variable length columns you would define the column as NAME VARCHAR(20). That would allow you to store up to 20 bytes for the NAME column.
This was first published in December 2002
Data Management Strategies for the CIO
Join the conversationComment
Share
Comments
Results
Contribute to the conversation