Is Character Varying the Same as Varchar?
When developers and database professionals discuss data types, character varying and varchar often appear together, sometimes interchangeably. In practice, this can lead to confusion, especially for those new to relational databases or SQL standards. To clear up the misunderstanding, this article explores the relationship between character varying and varchar, their origins, behavior, and practical implications in modern database systems Most people skip this — try not to..
What Is Character Varying?
Character varying is a SQL standard data type designed to store strings of variable length. The name itself hints at its purpose: it can hold characters, but the exact length can change from one row to another. In the SQL:2003 and later specifications, character varying is defined as:
- Maximum length: A user‑specified limit (e.g.,
VARCHAR(255)). - Storage: Only the characters actually used are stored, not the full allocated space.
- Collation: Supports language‑specific sorting and comparison rules.
Because it is part of the SQL standard, many database management systems (DBMS) implement it as a built‑in type. The standard uses the syntax CHARACTER VARYING (n) where n is the maximum size.
What Is Varchar?
Varchar (short for variable character) is the most common implementation of character varying in commercial databases. While the term “varchar” originated with IBM’s DB2 and later spread through MySQL, PostgreSQL, SQL Server, and Oracle, it essentially serves the same purpose: a variable‑length character string with a defined maximum length.
In practice, you’ll see VARCHAR(n) used in schema definitions across most platforms. Some databases even allow synonyms like VARCHAR2 (Oracle) or NVARCHAR for Unicode support.
Historical Context and Standardization
The split between the two terms stems from the evolution of SQL standards:
- Early IBM DB2 and Oracle introduced
VARCHARas a proprietary type to differentiate from fixed‑lengthCHAR. - SQL:92 formalized the concept as CHARACTER VARYING to create a common ground for different vendors.
- Later standards (SQL:1999, SQL:2003) retained CHARACTER VARYING as the official name, while allowing vendors to keep their own shorthand.
Thus, character varying is the standardized name, and varchar is the industry‑wide shorthand that most developers recognize.
Behavioral Similarities
Because they represent the same underlying concept, character varying and varchar behave almost identically in terms of:
- Length handling: Both store only the characters entered, up to the defined maximum.
- Padding: Neither pads the stored value with spaces to fill the maximum length.
- Comparison: Sorting and equality checks follow the same rules, respecting collations.
- Performance: Storage and indexing performance are comparable, as the engine treats them as variable‑length fields.
Key Differences You Might Encounter
| Aspect | Character Varying (SQL Standard) | Varchar (Vendor Implementation) |
|---|---|---|
| Syntax | CHARACTER VARYING (10) |
VARCHAR(10) |
| Documentation | Found in ANSI SQL specs | Used in vendor manuals |
| Unicode Support | May require explicit NATIONAL CHARACTER VARYING |
Often represented by NVARCHAR or NVARCHAR2 |
| Default Max Length | No default; must be specified | Some DBs allow VARCHAR without a length (e.g., MySQL) |
| Behavior in Queries | Treated identically by compliant engines | May have subtle dialect differences (e.g. |
Practical Implications for Developers
-
Schema Design
When writingCREATE TABLEstatements, you can use eitherCHARACTER VARYING(50)orVARCHAR(50). Most modern DBMS accept both, but sticking to one style improves readability for teams familiar with a particular dialect Simple, but easy to overlook.. -
Migration Between Systems
If you move a schema from PostgreSQL (which acceptsCHARACTER VARYING) to SQL Server (which prefersVARCHAR), a simple rename of the type usually works without data loss. -
Documentation and Comments
Use the term that matches your documentation. To give you an idea, Oracle’s documentation usesVARCHAR2, while the SQL standard referencesCHARACTER VARYING. Consistency avoids confusion for future maintainers Practical, not theoretical.. -
Indexing and Storage
Because both types store variable lengths, indexes are built similarly. That said, some databases (like MySQL) have aVARCHARthat can be indexed with a prefix length, a feature that may not be directly available forCHARACTER VARYINGin less common implementations.
Use Cases Where the Distinction Matters
- International Applications: When you need Unicode support, you might encounter
NATIONAL CHARACTER VARYING(standard) versusNVARCHAR(SQL Server) orNVARCHAR2(Oracle). Understanding the underlying character varying concept helps you choose the right Unicode type. - Legacy Systems: Older DB2 databases may still use
CHARACTER VARYINGin DDL scripts. Modern tools may require conversion toVARCHARfor compatibility. - Standard‑Compliance Projects: If you are developing software that must adhere strictly to SQL standards (e.g., for certification), using
CHARACTER VARYINGensures compliance, whereasVARCHARis a vendor‑specific alias.
Frequently Asked Questions
Q: Can I use CHARACTER VARYING and VARCHAR in the same database?
A: Yes. Most relational databases treat them as synonyms, so mixing them in a single schema is allowed and has no functional impact Less friction, more output..
Q: Does CHARACTER VARYING support case‑insensitive collations?
A: Like VARCHAR, it respects the collation defined for the column or database, allowing case‑sensitive or case‑insensitive comparisons based on the locale.
Q/topic: What about the default length?
A: The SQL standard requires an explicit length for CHARACTER VARYING. Some databases (e.g., MySQL) allow VARCHAR without a length, defaulting to a system‑defined maximum. Always specify a length for portability.
Q: Is there a performance difference?
A: No measurable difference in typical workloads. Both types are stored as variable‑length fields and indexed similarly And that's really what it comes down to..
Q: Can I change the length of a CHARACTER VARYING column after creation?
A: Yes, you can alter the column definition to increase or decrease the maximum length, subject to the database’s limitations (e.g., Oracle may restrict decreasing length if existing data exceeds the new limit).
Conclusion
In short, character varying and varchar are two names for the same data type: a variable‑length string with a user‑defined maximum size. The term character varying originates from the SQL standard, while varchar is the shorthand that most developers and database vendors use daily. Also, understanding this relationship helps you write portable schemas, communicate clearly with team members, and make informed decisions when working across different database platforms. Whether you write CHARACTER VARYING(255) or VARCHAR(255), you are describing a flexible, space‑efficient way to store text that adapts to the actual data you need to record Easy to understand, harder to ignore..