VARCHAR(length) Data
This is used for a character string that has a variable length. When you have data that will vary greatly in length and it is important to save disk space, the VARCHAR definition is used. If the maximum column length is small, then VARCHAR is probably not a good idea. If the maximum column length is large and most of the time the column will be blank, giving an average column length that is small, then a large amount of storage can be saved.
The (length) represents an integer for the maximum length of this column definition and must be 1 or greater.
Some DBMS systems limit this to 255 characters and use LONG VARCHAR for up to 32,767 characters.
Alphanumeric data can be stored in this definition.
If the length of the data entered into this column is shorter than the column definition, then the data is stored as is. For example, if the length is set to 200 characters and only 20 characters are entered, then the length of the data is recorded with the 20 characters of data.
VARCHAR is the same as CHAR VARYING and CHARACTER VARYING. We use VARCHAR in this course.
Example: COL1 VARCHAR(200)
COL1 is a maximum of 200 characters in length.
> Variable columns should be defined only at the end of a table.
> MySQL and SQL Server use VARCHAR.
> Oracle uses VARCHAR and VARCHAR2.