Variable Character Field

What Does Variable Character Field Mean?

A variable character field (varchar) is a data type which can contain any type of data: numeric, characters, spaces or punctuation. Depending on the database, the data type is capable of storing values up to its maximum size. Variable character fields are mostly used to act as temporary variables and for string operations. They bring in much-needed versatility for data field types.


Techopedia Explains Variable Character Field

A variable character field can be defined either in the programming language or on the database level. A variable character field always has a declared maximum length and is usually initialized with the current length equal to zero. The current length of the variable character field can be anything from zero to the maximum declared field length. The method of declaring a variable character field differs according to the programming language used.

One of the biggest advantages of variable character fields is the avoidance of padding. In the case of a character field, the field occupies the exact number of characters regardless of the actual size of the string, and the difference between the fixed length and field length is padded with spaces. Unlike a character field, a variable character field only utilizes the space required for the size of the string, so only the minimum storage space is required. It helps in avoiding any wastage, and this feature is helpful in searching and sorting of values. In some databases and programming languages, any extra space found is automatically removed before storing to the database.

Based on the database or the programming language, there could be limitations on a variable character field, such as it cannot be used with select statement or cannot be used as a candidate or primary key.

Most relational database management systems support the variable character field.


Related Terms

Latest Database Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…