VARCHAR (or CHARACTER VARYING) is a standard SQL data type used to store character strings whose length can vary per row, up to a user-defined limit. Unlike CHAR, which pads unused space with blanks, VARCHAR uses only as much space as needed plus a small length header, making it more space-efficient for columns where string lengths differ significantly. Each RDBMS enforces its own maximum length (often 65,535 in MySQL, 2 GB in PostgreSQL and SQL Server) and may differ in whether trailing spaces are preserved or trimmed. When defining a VARCHAR column you must specify a positive integer length. If a value longer than this length is inserted, the database either truncates the data or throws an error, depending on the dialect and SQL mode. VARCHAR participates in collation and character-set rules just like other character types. Because storage is length-prefixed, random updates that increase row size can cause page splits or row overflow in some engines, a performance consideration on very large tables.
n
(integer) - Required maximum number of characters that each stored string can hold.CHAR, TEXT, NVARCHAR, VARCHAR2, CHARACTER VARYING
SQL-92
CHAR stores fixed-length strings and pads unused space with blanks, while VARCHAR stores variable-length strings without padding, saving storage when values differ in length.
For small strings, CHAR can be marginally faster due to fixed width. For varied lengths, VARCHAR reduces I/O and usually offers better overall performance.
Yes. Use ALTER TABLE to modify the column length. Increasing length is safe; decreasing may fail if data exceeds the new limit.
Most modern databases allow specifying a Unicode character set (e.g., UTF8) on the column or database level. VARCHAR then stores multibyte characters transparently, with the length limit still defined in characters (not bytes).