Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Difference between Char and Varchar? [duplicate]

Tags:

Possible Duplicate:
What's the difference between VARCHAR and CHAR?

what is the difference between CHAR and VARCHAR.

like image 327
HELP Avatar asked Oct 08 '10 04:10

HELP


People also ask

What is the difference between CHAR and VARCHAR?

What's the difference between CHAR and VARCHAR? The short answer is: VARCHAR is variable length, while CHAR is fixed length. CHAR is a fixed length string data type, so any remaining space in the field is padded with blanks.

Which is better CHAR or VARCHAR?

CHAR is a fixed length field; VARCHAR is a variable length field. If you are storing strings with a wildly variable length such as names, then use a VARCHAR, if the length is always the same, then use a CHAR because it is slightly more size-efficient, and also slightly faster.

Is VARCHAR more efficient than CHAR?

Because of the fixed field lengths, data is pulled straight from the column without doing any data manipulation and index lookups against varchar are slower than that of char fields. CHAR is better than VARCHAR performance wise, however, it takes unnecessary memory space when the data does not have a fixed-length.

Why would you use CHAR instead of VARCHAR?

If you use char or varchar, we recommend to: Use char when the sizes of the column data entries are consistent. Use varchar when the sizes of the column data entries vary considerably. Use varchar(max) when the sizes of the column data entries vary considerably, and the string length might exceed 8,000 bytes.


1 Answers

A CHAR field is a fixed length, and VARCHAR is a variable length field.

This means that the storage requirements are different - a CHAR always takes the same amount of space regardless of what you store, whereas the storage requirements for a VARCHAR vary depending on the specific string stored.

like image 111
Mark Byers Avatar answered Sep 20 '22 21:09

Mark Byers