yes that's the general rule. and even i was under the impression that char would
be faster so should be used when it comes to fixed size data. what i was
wondering about certain statements that i came across, which claimed that char
internally uses varchar. in that case, it would always be beneficial to go with
varchar. so just wanted to check if some1 has first-hand figures on performance
:)
maybe not everything on discussion forums can be relied on ;) or maybe they had
specific DB in mind.
anyways thanks.
cheers,
amey
________________________________
From: ashutosh <ashutosh9910@...>
To: NCST@yahoogroups.com
Sent: Thursday, 9 July, 2009 10:39:02 PM
Subject: [NCST] Re: [query] char vs varchar in DB
Here is what I found ....
As a general rule, you would pick CHAR if all rows will have the same length and
VARCHAR when it is variable length.
CHAR is also a bit faster.
It actually varies by DB implementation, but generally VARCHAR uses one or two
more bytes of storage (for length or termination) then CHAR.
So (assuming you are using ANSI character set) to store the word "FooBar" in a
CHAR(6) is 6 bytes. To store the same word in VARCHAR(10) would be 7 bytes. But
to store "FooBar" in a CHAR(10) would be 10 bytes.
Bottom line is CHAR can be faster and more space efficient for fixed with data
than VARCHAR.
Thanks
Ashutosh
--- In NCST@yahoogroups. com, amey samant <ameyas7@... > wrote:
>
> Hi All,
>
> i wanted to know if and how does choosing char over varchar impacts the
performance.
> i have some data which will be fixed size (may contain null). i know the
ground rule that varchar should be used for variable length data (that was back
in playschool ... :) jus kiddin)
> what i am looking for is if and how much does char can improve performance if
we have fixed length data against using varchar for such column.
> one simple reason i got is that for varchar, DB will maintain length so there
is an overhead of reading length first n then reading tht many chars of data. i
did browse through lot of discussion forums, some of them claim to say that db
internally uses varchar even for char. however i really doubt if thats the case
for all DB. heres one such thread
> http://sql-server- performance. com/Community/ forums/p/ 4260/28443. aspx
>
>
> im sure many of us have already gone through this ... some might have even
designed their own DB ;)
> any inputs are welcome. if you have inputs specific to sybase or MS SQL sever,
that will be gr8.
> thanks.
>
>
> regards
> amey
>
> Be the change you wish to see in others.
> - Mahatma Gandhi
>
>
> blogspot me at-: http://ameyas7. blogspot. com
>
>
>
> Looking for local information? Find it on Yahoo! Local http://in.local.
yahoo.com/
>
> [Non-text portions of this message have been removed]
>
Yahoo! recommends that you upgrade to the new and safer Internet Explorer
8. http://downloads.yahoo.com/in/internetexplorer/
[Non-text portions of this message have been removed]