MySQL Data Types - VARCHAR

Versions: MySQL 5.x, 4.x and 3.23

MySQL - VARCHAR
Syntax VARCHAR(n) [CHARACTER SET charset | BINARY | ASCII | UNICODE ] [COLLATE collate]
Data Variable-length character data, single-byte and multibyte character sets
Parameters n is the maximum number of characters, optional. CHARACTER SET specifies the character set, COLLATE specifies a collation for the character set.

ASCII is equal to CHARACTER SET latin1, UNICODE is equal to CHARACTER SET ucs2, BINARY is equal to specifying the binary collation
Range 1 ⇐ n ⇐ 65535/charsize (65535 is the maximum row size shared among all columns)
Default n is mandatory
Padding Not right-padded with spaces to n
Trailing Spaces Not removed when the value is stored and retrieved. But trailing spaces are insignificant in comparisons, primary and unique keys
Error Handling Exceeding data truncated and a warning is generated if strict SQL mode is not enabled, otherwise in case of non-space characters truncation, an error is raised

If strict SQL mode is not enabled, a VARCHAR column with a length greater than 65535 is converted to TEXT, otherwise an error is generated
Storage Size Actual entry length
Internals If CHARACTER SET binary is specified, it is automatically converted to the VARBINARY data type without warning
Version Differences MySQL 4.1 and later - CHARACTER SET and COLLATE options are available.
MySQL 4.0.2 and earlier - 1 ⇐ n ⇐ 255
Synonyms CHAR VARYING, CHARACTER VARYING
Standards ANSI SQL

MySQL VARCHAR - Equivalents in Other Databases

Database Data Type and Conversion
Oracle VARCHAR2(n), 1 ⇐ n ⇐ 4000/charsize
SQL Server VARCHAR(n | max), 1 ⇐ n ⇐ 8000, 2G if max is specified
PostgreSQL VARCHAR(n), 1 ⇐ n ⇐ 1G
Sybase ASE VARCHAR(n), 1 ⇐ n ⇐ pagesize (2K, 4K, 8K or 16K)
Informix VARCHAR(n,r), 1 ⇐ n ⇐ 255, LVARCHAR(n), 1 ⇐ n ⇐ 32739
HP Neoview VARCHAR(n), 1 ⇐ n ⇐ (32708 - size of other columns)

Related Data Types in MySQL

Data Types
Fixed-length character data CHAR(n) NCHAR(n)
Variable-length character data NVARCHAR(n) TINYTEXT TEXT MEDIUMTEXT
Character large objects LONGTEXT

All Data Types

Oracle SQL Server IBM DB2 MySQL PostgreSQL Sybase ASE Sybase ASA Informix DS Teradata HP Neoview Interbase/Firebird


SQLWays Product Page - Migration to MySQL Free Evaluation

Discussion

Enter your comment:
TCXVT
 
sqlways/mysql/data-types/varchar_n.txt · Last modified: April 25, 2012, 04:44:57 AM (external edit)
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki