What is the difference between CHAR and VARCHAR?

What is the difference between CHAR and VARCHAR?

CHAR and VARCHAR are two different functions that can be used in SQL. The primary usage of both is to store characters. The CHAR function is better suited to store fixed length characters, whereas VARCHAR is better suited to store variable length characters. The following are the primary differences between the two:

CHAR

VARCHAR

Fixed length

Variable-length

Better suited if content is fixed size

Better suited if content is variable size

Used to store character string value of fixed length.

Used to store variable length alphanumeric data.

The maximum number of characters the data type can hold is 255 characters.

Pre-MySQL 5.0.3 can hold a maximum of 255 characters. After MySQL 5.0.3, can hold 65,535 characters shared for the row.

Is faster than VARCHAR.

Is slower than CHAR

Uses static memory allocation

Uses dynamic memory allocation

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.