What is the difference between CHAR and VARCHAR datatype in MySQL?

Some of the main differences between CHAR and VARCHAR datatypes in MySQL are as follows:

  • Size: In a CHAR type column, length is fixed. In a VARCHAR type column length can vary.
  • Storage: There are different mechanisms to store and retrieve CHAR and VARCHAR data types in MySQL.
  • Maximum Size: A CHAR data type can hold maximum 255 characters. A VARCHAR datatype can store up to 4000 characters.
  • Speed: CHAR datatype is 50% faster than VARCHAR datatype in MySQL.
  • Memory Allocation: A CHAR datatype column uses static memory allocation. Since the length of data stored in a VARCHAR can vary, this datatype uses dynamic memory allocation.
Read the full book at www.amazon.com
Posted in MySQL, MySQL Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

*