Up Prev Next
From: M Brown <m-brown1 at ais-1 dot uchicago dot edu>
Subject: Re: Size of null char field
Date: Apr 29 1998 1:19PM
Lee is correct :
This is an except from Sybooks :
"Length and Storage Size
This example illustrates how the column's datatype and null type interact
to determine how blank spaces are treated:
ˇOnly char not null and nchar not null columns are padded to the full
width of the column; char null columns are treated like varchar and
nchar null columns are treated like nvarchar.
ˇPreceding blanks are not affected.
ˇTrailing blanks are truncated except for char and nchar not null
ˇThe empty string ("") is treated as a single space. In char and nchar
not null columns, the result is a column-length field of spaces."
- Michael Brown
Brown Computer Consulting
ex-SQL Solutions/Sybase Co. Consultant
At 01:08 PM 4/28/98 -0700, Lee Falkenhagen wrote:
>Sybase stores null fields as varchars. That means, if you define a
>column as char(3) null, it still stores it as varchar. Sybase uses one
>byte for each space in a character field. It also stores one byte if
>field is null. In other words, if you have a field that is char(3) null
>vs char(3) not null, the first uses 4 bytes and the second uses 3 bytes
>if the field is completely filled. However, if the char(3) null only
>a value of "I", than only two bytes are used.
>I am doing this off the top of my head. Check sybooks.sybase.com and
>look in the Reference Guide for exact storage requirements under "Data
>Certified Sybase Professional
>On Tue, 28 Apr 1998, Michael Peppler wrote:
>> Mick Ghazey writes:
>> > How big is a char field that allows nulls? The reason I ask is
>> > sybperl returns trailing spaces to fill out the column to the
>> > width for not null fields. Yet it returns only the actual string
>> > null fields. Does that imply that sybase uses less disk space for
>> > fields?
>> As I believe others have reported, Sybase stores nullable char
>> as varchars, which is the reason why they don't get padded with ' ' to
>> the actual maximum width. I'm not 100% sure if varchar fields use less
>> space than char fields, but I think so (at least if they are not
>> completely filled...)
>> Michael Peppler -||- Data Migrations Inc.
>> firstname.lastname@example.org -||- http://www.mbay.net/~mpeppler
>> Int. Sybase User Group -||- http://www.isug.com