Character Types
Last updated
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:
Fixed-length character types
Variable-length character types
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).
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.
Stores large text data (longer than VARCHAR(n) limits).
Not part of standard SQL but supported by many databases.
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