473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Datatype difference

xploreraj
Hi,
I have one confusion. What is the difference between varchar and char? I have observed that both work similarly, a varchar won't take more than specified no. of characters.
And one more thing, what should be the data type that can take in varying number of values?

Thanks,
xploreraj
Sep 20 '10 #1
3 1474
code green
1,726 Expert 1GB
It just seems to be down to memory allocation.
VARCHAR (n) will allocate memory for UPTO n characters
CHAR (n) will ALWAYS allocate memory for n characters.
CHAR has a max of 255 characters, VARCHAR has more in later versions.
This may help some more.
http://dev.mysql.com/doc/refman/5.0/en/char.html
I seem to remember it is more efficient to use CHAR.
Sep 21 '10 #2
Atli
5,058 Expert 4TB
I seem to remember it is more efficient to use CHAR.
Depends on what you are trying to optimize.

VarChar is a variable size field, whereas Char is fixed size. As such, Char will usually use more disk space. So if you are worried about the size of the database, VarChar would be the better choice.

However, if all the columns in your table are fixed size, it *may* increase the speed at which MySQL can read the table. For each row it reads, MySQL has to detect the total size of the data. If all the rows are fixed, it can do this once for all the rows using only the column definitions. If the table contains a variable size column, it has to do this for each row by inspecting the actual data (or it's meta-data).

So, essentially:
- Use VarChar to conserve disk space
- Use Char to optimize read speed.

That second one is, as I explained, dependent on the other rows not being variable size as well.
Sep 24 '10 #3
Thanks Code Green and Atli for the details, just cleared my concept, thanks a lot.
Sep 28 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Elias Farah | last post by:
Hi All, What are people's experience in timing Query Performance? I have tried in vain, but get many unpredictable results, with execution proceeding in the background and problems of timing...
8
by: MLH | last post by:
If I choose to dim MyDate as Date or MyDate as Variant, what is the most significant difference between the two choices?
13
by: Madison Kelly | last post by:
Hi again, Something I have been wondering about and haven't found an answer to yet is how the size of a datatype (I hope that is the right term) effects performance. What effect is there if I...
1
by: Alan | last post by:
Is there any difference in these: private string string1; private String string2: I found the colors of the 'string' and 'String' are different.
1
by: James | last post by:
just wondering if there was a difference, if so, could I see an example? Thanks.
9
by: Andreas Vinther | last post by:
I have a small piece of code that compiles but does not perform like I want it to. This code works: ---------------- void *y0; void *y1; void *y2; void *y3;
2
kiss07
by: kiss07 | last post by:
Hi, Any body Send reply.. What is difference between datatype Time and TimeStamp? Regards, Kiss07
5
by: tim007 | last post by:
hi all, As we design a database I have a field for storing the last name, so i give the datatype varchar (50) now my question is there any difference if i were use varchar (200) instead...
1
by: pulavarthipraveen | last post by:
When I tried to change the datatype of the column through "Alter table tablename Alter column columnname Newdatatype" query it's is throw the error below: "The index 'IndexName' is dependent on...
5
by: bullfrog83 | last post by:
In my one table I have a Yes/No field that I need to use in VBA. When I dim the variable which datatype should I use? Byte or boolean? I'd be inclined to use boolean but it's 2 bytes whereas byte...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.