34

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

what is the difference between CHAR and VARCHAR.

Community
  • 1
  • 1
HELP
  • 14,237
  • 22
  • 66
  • 100

2 Answers2

63

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.

Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • 18
    So why do we need to use CHAR ? – Hayk Aramyan Sep 16 '15 at 10:44
  • 62
    @HaykAramyan Because CHAR fields are stored inside the register due to its size being known, this makes searching and indexing faster. VARCHAR have to be stored elsewhere and reference tables have to be used to find the content. – Petruza Jan 24 '17 at 16:14
9

VARCHAR stores a variable number of bytes for only the space required by the content.

CHAR stores a fixed size of however many bytes you specify for your table, no matter how many characters occupy a field of this type per row.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356