- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between CHAR and VARCHAR in MySQL?
CHAR and VARCHAR are both ASCII character data types and almost same but they are different at the stage of storing and retrieving the data from the database. Following are some important differences between CHAR and VARCHAR in MySQL −
CHAR Data Type
VARCHAR Data Type
|Its full name is CHARACTER||Its full name is VARIABLE CHARACTER|
|It stores values in fixed lengths and are padded with space characters to match the specified length||VARCHAR stores values in variable length along with 1-byte or 2-byte length prefix and are not padded with any characters|
|It can hold a maximum of 255 characters.||It can hold a maximum of 65,535 characters.|
|It uses static memory allocation.|
mysql>create table emp(name CHAR(20)); Query OK, 0 rows affected (0.25
|It uses dynamic memory allocation.|
mysql>create table emp1(name VARCHAR(20)); Query OK, 0 rows affected (0.21
- What is the difference between CHAR and NCHAR in MySQL?
- Difference between char s and char *s in C
- What should one use CHAR data type or VARCHAR data type in MySQL?
- Difference between const char* p, char * const p, and const char * const p in C
- Difference between string and char types in C++
- What is the difference between SQL and MySQL?
- What is the MySQL VARCHAR max size?
- In MySQL, what is the difference between SERIAL and AUTO_INCREMENT?
- What is the difference between int and integer in MySQL?
- What is the difference between BIT and TINYINT in MySQL?
- What is the difference between MySQL NOW() and SYSDATE()?
- What is the reverse function of CHAR() in MySQL
- What is the use of MySQL CHAR() function?
- In MySQL what is the difference between != NULL and IS NOT NULL?
- What is the difference between TINYINT(1) and Boolean in MySQL?