liveBook · Manning

Varchar data type

As explained in Learn SQL in a Month of Lunches

VARCHAR is a variable-length SQL character data type that stores text using only the space needed for each value.

VARCHAR stores text values whose lengths vary. Unlike CHAR, it uses space for the value rather than the column’s entire defined length, making it a practical choice for names such as category labels. section 18.1.1

For predictable table design, give VARCHAR a maximum length. A column declared as varchar(20) allows category names up to 20 characters and avoids relying on an inefficient database-specific default. section 18.1.1

A category table

CREATE TABLE category defines CategoryID as int and CategoryName as varchar(20). In plain English, the table stores a numeric identifier alongside a text category name limited to 20 characters. Running the statement creates the table without returning result rows; a successful database interface reports completion separately. section 18.1.2

CREATE TABLE category (
    CategoryID int,
    CategoryName varchar(20)
    );

Use this complete CREATE TABLE example to see VARCHAR applied beside an integer column and the required parentheses and comma-separated definitions. section 18.1.2

How Learn SQL in a Month of Lunches covers it

How deep it goes
Explains storage efficiency, maximum lengths, and basic CREATE TABLE usage, while deferring additional table properties.
Examples
Uses a category table with CategoryName varchar(20) beside CategoryID int.
What it assumes
Assumes basic awareness of tables, columns, and SQL statements while explaining data types through a concrete table definition.
What you can do after
Build a basic table with a bounded variable-length text column using CREATE TABLE.
How it connects
Connects VARCHAR with CHAR, CREATE TABLE, columns, data types, and relational database management systems.

Also explained in

Compare how 4 books explain varchar data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn SQL in a Month of Lunches. The section links point to the parts of the book it draws on.