Sql - CREATE TABLE and data types
Code Life
By Pierre Marsaa
Your first table
So far every table was already there. CREATE TABLE builds a new one: the table name, then one line per column with its name and its type.
Statements that define the structure of the database (CREATE, ALTER, DROP) are called DDL, Data Definition Language.
The league needs a gyms table:
↗️
Loading editor...
↶
↷
The table is created empty; the INSERT fills it with two rows. gym_id INTEGER PRIMARY KEY is the automatic id you have been using all along — NOT NULL and PRIMARY KEY are constraints, rules attached to a column. More on them in the next chapter.
To see which tables exist, ask the database's own catalog:
↗️
Loading editor...
↶
↷
Already there?
CREATE TABLE gyms … fails if gyms already exists. CREATE TABLE IF NOT EXISTS gyms … does nothing in that case, without an error — handy in scripts you run more than once.
Verify