0

What's the difference between char and varchar in phpmyadmin ?

I am trying to decide whether to use char or varchar for name for example.

Edited by pritaeas: Moved to MySQL.

4
Contributors
5
Replies
30
Views
4 Years
Discussion Span
Last Post by RomelynCastillo
0

Char allocates a fixed length string as defined, whereas varchar uses a string length upto it's defined size.

0

Then it's better to use varchar then (compare to char), since it saves more space, adjusting the required space as needed.

0

If your field values are all the same length then use CHAR. Something like a postal code or a car licence plate would be suitable for CHAR, whereas a name or address should be a VARCHAR or NVARCHAR.

0

CHAR- You specify how many characters you want the field to hold. The maximum value is 255. For example:

CHAR(10)

This field can then hold a maximum of ten characters. But if you only use 4 of them, the rest of the 10 characters will be blank spaces. The blank spaces get added to the right of your text:

"TEXT "

"TENLETTERS"

VARCHAR- Like CHAR, but the rest of the characters are not padded with blank spaces. The maximum value before MySQL 5.0.3 was 255. After this it's jumped to 65, 535. With VARCHAR, there is also an extra byte that records how long your text is.

For our fields, then, we'll use the following Types:

ID SMALLINT
First_Name VARCHAR
Surname VARCHAR
Address TINYTEXT

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.