Here’re the differences between CHAR and VARCHAR. You can use these to store strings. For instance, names are one such kind of data.
CHAR data type
The CHAR data type pads space when the moved string is shorter. Let us say you have created emp_name with CHAR of 20.
Here, I moved ‘Vani Mohan’ to the emp_name. The first 10 bytes will have actual string, and the next 10 bytes will be spaces.
VARCHAR data type
The VARCHAR works the other way round of CHAR. Let us say the emp_name column you defined as VARCHAR(20).
When you move ‘Vani Mohan’ to the emp_name, it stores the string as two parts. One is length, and another part is an actual string.
==> Length (2 bytes) + Actual string
When you move 'VANI MOHAN' to emp_name. It occupies internally as
first 2 bytes is length and rest 10 bytes will be actual length.
The VARCHAR doesn’t pad spaces when the string length supplied is shorter.
- The maximum for CHAR is 255 bytes
- The VARCHAR’s maximum size depends on the page size
The CHAR and VARCHAR improve performance if you use them correctly.
Top organic products
For healthy and stylish life style.