Is Character Varying Same As Varchar

5 min read

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:

  1. Early IBM DB2 and Oracle introduced VARCHAR as a proprietary type to differentiate from fixed‑length CHAR.
  2. SQL:92 formalized the concept as CHARACTER VARYING to create a common ground for different vendors.
  3. 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

  1. Schema Design
    When writing CREATE TABLE statements, you can use either CHARACTER VARYING(50) or VARCHAR(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..

  2. Migration Between Systems
    If you move a schema from PostgreSQL (which accepts CHARACTER VARYING) to SQL Server (which prefers VARCHAR), a simple rename of the type usually works without data loss.

  3. Documentation and Comments
    Use the term that matches your documentation. To give you an idea, Oracle’s documentation uses VARCHAR2, while the SQL standard references CHARACTER VARYING. Consistency avoids confusion for future maintainers Practical, not theoretical..

  4. Indexing and Storage
    Because both types store variable lengths, indexes are built similarly. That said, some databases (like MySQL) have a VARCHAR that can be indexed with a prefix length, a feature that may not be directly available for CHARACTER VARYING in less common implementations.

Use Cases Where the Distinction Matters

  • International Applications: When you need Unicode support, you might encounter NATIONAL CHARACTER VARYING (standard) versus NVARCHAR (SQL Server) or NVARCHAR2 (Oracle). Understanding the underlying character varying concept helps you choose the right Unicode type.
  • Legacy Systems: Older DB2 databases may still use CHARACTER VARYING in DDL scripts. Modern tools may require conversion to VARCHAR for compatibility.
  • Standard‑Compliance Projects: If you are developing software that must adhere strictly to SQL standards (e.g., for certification), using CHARACTER VARYING ensures compliance, whereas VARCHAR is 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..

Just Dropped

Just Landed

See Where It Goes

More to Discover

Thank you for reading about Is Character Varying Same As Varchar. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home