Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

CREATE TABLE

Before we can add data to our database we need to create one or more tables to hold the data. For this we use the DDL (Data Definition Languagea), which part of the SQL language, of dialect in the database system we use.

The statement starts with CREATE TABLE followed by the name of the table. Then in parenthese we have the name and the type of each column. Optionally we can have comments after two dash-es.

Some of the popular column types:

  • ENUM
  • VARCHAR
  • FLOAT
  • INTEGER
  • DATE
CREATE TABLE person (
    name       VARCHAR(100),
    height     FLOAT,         -- in meter
    weight     INTEGER,       -- in kg
    birthday   DATE,
    occupation VARCHAR(100),
    gender     ENUM('male', 'female')
);