SR.NO. | CHAR | VARCHAR |
1. | CHAR datatype is used to store character strings of fixed length | VARCHAR datatype is used to store character strings of variable length |
2. | In CHAR, If the length of the string is less than the set or fixed length then it is padded with extra memory space. | In VARCHAR, If the length of the string is less than the set or fixed length then it will store as it is without padding with extra memory spaces. |
3. | CHAR stands for “Character” | VARCHAR stands for “Variable Character” |
4. | Storage size of CHAR datatypes is equal to n bytes i.e. set length | The storage size of the VARCHAR datatype is equal to the actual length of the entered string in bytes. |
5. | We should use the CHAR datatype when we expect the data values in a column are of the same length. | We should use the VARCHAR datatype when we expect the data values in a column are of variable length. |
6. | CHAR takes 1 byte for each character | VARCHAR takes 1 byte for each character and some extra bytes for holding length information |
9. | Better performance than VARCHAR | Performance is not good as compared to CHAR |
CHAR vs VARCHAR datatypes in MySQL:
VARCHAR saves space when there is variation in the length of values, but CHAR might be performance-wise better.
Related Posts
Search
Subscribe for Updates
Categories
Facebook Post