SQL Server CHAR and VARCHAR

Asked

Viewed 315 times

4

I understood the difference between CHAR and VARCHAR.

If I want to insert in a field VARCHAR(10) the word 'house', that word in the bank will take 4 bytes.

If I want to insert in a field CHAR(10) the word 'house', that word in the bank will occupy 10 bytes.

It is quite clear the difference for me, my only doubt is that amount of bytes compared to the NULL. If I leave the field VARCHAR NULL will stay 0 bytes, in the case of CHAR will stay 10 bytes locked even though NULL?

1 answer

2

If the field is fixed(CHAR) NULL size has the same space as any other value - the field size.

If field is of variable size(VARCHAR) the NULL value does not take up space.

In addition to the space required to store a null value, there is also an overhead of having a null column. For each row a little is used by voidable column to mark whether the value for that column is null or not. This is true if the column is fixed or variable length.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.