Search the web
Sign In
New User? Sign Up
NCST · National Centre for Software Technology
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want to share photos of your group with the world? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
[query] char vs varchar in DB   Message List  
Reply | Forward Message #10655 of 10700 |
Re: [NCST] Re: [query] char vs varchar in DB

IMHO, Internally using varchar to implement char will defeat the entire
purpose of char. Also it seems to a really convoluted design for
implementing char.
Regards
Amrit

2009/7/10 amey samant <ameyas7@...>

>
>
> 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@... <ashutosh9910%40yahoo.com>>
> To: NCST@yahoogroups.com <NCST%40yahoogroups.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]
>
>
>



--
मंगल भवन, अमंगल हारी !!


[Non-text portions of this message have been removed]




Fri Jul 10, 2009 5:24 am

snoopy_singh
Offline Offline
Send Email Send Email

Forward
Message #10655 of 10700 |
Expand Messages Author Sort by Date

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...
amey samant
ameyas7
Offline Send Email
Jul 9, 2009
7:20 am

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...
ashutosh
ashutosh9910
Offline Send Email
Jul 9, 2009
5:09 pm

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...
amey samant
ameyas7
Offline Send Email
Jul 10, 2009
4:48 am

IMHO, Internally using varchar to implement char will defeat the entire purpose of char. Also it seems to a really convoluted design for implementing char. ...
अमृत ...
snoopy_singh
Offline Send Email
Jul 10, 2009
5:25 am

... remember also that a char(x) NULL column is actually a varchar(x) NULL column. A char column is incapable of holding a null, so behind the scenes SQL will...
Vivek Athalye
vnathalye
Offline Send Email
Jul 10, 2009
5:42 pm

yes that was the post that caught my attention. however if your interpretation is right, then it will be a pain (from implementation point of view of DB) if...
amey samant
ameyas7
Offline Send Email
Jul 10, 2009
7:46 pm

Per MSDN, If ANSI_PADDING is ON when a char NULL column is created, it behaves the same as a char NOT NULL column: values are right-padded to the size of the...
ashutosh
ashutosh9910
Offline Send Email
Jul 13, 2009
6:21 am
Advanced

Copyright 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help