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.

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

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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.