CHAR vs VARCHAR in SQL

Last Updated : 18 Sep, 2026

In SQL, CHAR and VARCHAR are character string data types used to store text values in a database. Although both are used to store strings, they differ in how they handle the length and storage of data.

  • CHAR stores character strings of fixed length.
  • VARCHAR stores character strings of variable length.
  • The choice between them depends on the nature and expected length of the data.

CHAR Datatype

The CHAR datatype is used to store character strings of a fixed length specified when defining the column.

  • It stores values using the defined fixed length.
  • It is suitable for data where values generally have a fixed or consistent length.

Example

Consider the following query:

CREATE TABLE student (
name VARCHAR(30),
gender CHAR(6)
);

INSERT INTO student VALUES ('Herry', 'Male');
INSERT INTO student VALUES ('Mahi', 'Female');

SELECT Length(gender) FROM student;

Output:

Screenshot-2026-09-17-153605
  • Here, Gender is defined as CHAR(6), so both values are handled using the defined fixed length.

VARCHAR Datatype

The VARCHAR datatype is used to store character strings of variable length, up to the maximum length specified.

  • It stores values according to their actual length.
  • It is suitable for data where the length of values varies.

Example

Consider the following query:

CREATE TABLE student (
name VARCHAR(20),
Gender CHAR(6)
);

INSERT INTO student VALUES ('Herry', 'Male');
INSERT INTO student VALUES ('Mahi', 'Female');

SELECT Length(name) FROM student;

Output:

Screenshot-2026-09-17-153821
  • Here, name is defined as VARCHAR(20), but the actual values have lengths of 5 and 4 characters.

CHAR vs. VARCHAR Datatypes

The following table highlights the key differences between CHAR and VARCHAR datatypes based on their length, storage and usage.

CHARVARCHAR
CHAR is used to store character strings of fixed length.VARCHAR is used to store character strings of variable length.
Values are stored using the defined fixed length.Values are stored according to their actual length.
CHAR(n) defines a fixed character length of n.VARCHAR(n) defines a maximum character length of n.
Suitable for data with a fixed or consistent length.Suitable for data with varying lengths.
Storage is based on the defined length and character set.Storage is based mainly on the actual value length and length information.
Can be useful when values have a consistent length.Can be more storage-efficient when values have varying lengths.
Comment

Explore