Character Types

About

Character data types are used to store textual data, such as names, addresses, and descriptions. SQL provides standard character types that most relational databases support, with slight variations.

There are two main categories:

  1. Fixed-length character types

  2. Variable-length character types

1. CHAR(n)

  • Stores fixed-length character strings.

  • Always occupies n characters, padding with spaces if input is shorter.

  • Use when all values are known to have the same length (e.g., status codes, country codes).

Example: CHAR(5) will store 'abc' as 'abc ' (with two spaces).

2. VARCHAR(n) or CHARACTER VARYING(n)

  • Stores variable-length character strings.

  • Maximum length is n, but only uses as much space as needed.

  • More efficient for storing strings of varying length.

Example: VARCHAR(10) can store 'abc' using 3 characters instead of 10.

3. TEXT (non-standard, vendor-specific)

  • Stores large text data (longer than VARCHAR(n) limits).

  • Not part of standard SQL but supported by many databases.

Vendor Support Overview

Database

CHAR

VARCHAR

TEXT Support

Notes

Oracle

Yes

Yes

No TEXT; use CLOB

Oracle uses CLOB for large character data. VARCHAR2 is preferred.

MySQL

Yes

Yes

Yes

Supports TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT.

PostgreSQL

Yes

Yes

Yes

TEXT has no length limit and behaves like unlimited VARCHAR.

SQL Server

Yes

Yes

Yes (TEXT deprecated)

Use VARCHAR(MAX) instead of TEXT.

SQLite

Yes

Yes

Yes

Very flexible typing; TEXT used commonly.

Last updated

Was this helpful?