I have a database which was 120 MB before changed the data
types on some columns in some tables. I have changed
the 'char' data types to 'varchar' data type on many
columns expecting the database size to get smaller.
Instead, it went up from 120 MB to 131 MB (This is the
pure data part not the space allocation part).
Did I understand the data types wrong '
Thanks for any help..No - you have probably understood the types correctly, but changing from =char to varchar will have 2 effects:
1 An extra 2 bytes per varchar column will be allocated for the length =data of each column, thus the row will potentially increase in size and =may cause extra pages to be allocated as a result.
2. The char colukns are padded with spaces so to get rid of those you =will ned to do Update x set col=3Drtrim(col) on each column you have =changed.
Fnally having done 1 and 2 drop and recreate the clustered index (if =any) to force the rows to be re-allocate dto new pages with theire =reduced (hopefully) sizes. If no CI exists then create one and drop it =again to have the same effect.
Mike John
"calvin" <anonymous@.discussions.microsoft.com> wrote in message =news:008e01c3c96d$bc5a7950$a101280a@.phx.gbl...
> I have a database which was 120 MB before changed the data > types on some columns in some tables. I have changed > the 'char' data types to 'varchar' data type on many > columns expecting the database size to get smaller. > Instead, it went up from 120 MB to 131 MB (This is the > pure data part not the space allocation part).
> > Did I understand the data types wrong '
> > Thanks for any help..
> >|||Thanks Mike......
>--Original Message--
>No - you have probably understood the types correctly,
but changing from char to varchar will have 2 effects:
>1 An extra 2 bytes per varchar column will be allocated
for the length data of each column, thus the row will
potentially increase in size and may cause extra pages to
be allocated as a result.
>2. The char colukns are padded with spaces so to get rid
of those you will ned to do Update x set col=rtrim(col) on
each column you have changed.
>Fnally having done 1 and 2 drop and recreate the
clustered index (if any) to force the rows to be re-
allocate dto new pages with theire reduced (hopefully)
sizes. If no CI exists then create one and drop it again
to have the same effect.
>Mike John
>"calvin" <anonymous@.discussions.microsoft.com> wrote in
message news:008e01c3c96d$bc5a7950$a101280a@.phx.gbl...
>> I have a database which was 120 MB before changed the
data
>> types on some columns in some tables. I have changed
>> the 'char' data types to 'varchar' data type on many
>> columns expecting the database size to get smaller.
>> Instead, it went up from 120 MB to 131 MB (This is the
>> pure data part not the space allocation part).
>> Did I understand the data types wrong '
>> Thanks for any help..
>>
>.
>
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment