sql / beginner
Snippet
Storing Fixed-Length Text Values using CHAR
The CHAR data type allocates a fixed amount of character storage. It is ideal for columns where string entries always have identical lengths, such as ISO country codes or state abbreviations.
snippet.sql
sql
1
2
3
CREATE TABLE countries (country_code CHAR(2) NOT NULL);
Breakdown
1
CREATE TABLE countries (
Initiates the creation of a new table named 'countries'.
2
country_code CHAR(2) NOT NULL
Defines a column that strictly stores strings of exactly two characters.
3
);
Closes the table definition statement.