Lesson 12 of 22 · SQLite

CREATE TABLE

Create tables with SQL CREATE TABLE, PRIMARY KEY, NOT NULL and DEFAULT, then insert rows.

Syntax

CREATE TABLE table_name (
    column1 datatype constraints,
    column2 datatype constraints
);

Common Constraints

  • PRIMARY KEY — unique identifier
  • NOT NULL — cannot be empty
  • UNIQUE — no duplicates
  • DEFAULT — fallback value

Your challenge

Create a table called pets with three columns, in this order: id (integer primary key), name (text, NOT NULL) and species (text). Then add a dog named Rex and a cat named Tom.

Solve it in your browser

Free, no sign-up. The SQLite database runs in your browser; your answer is checked instantly, with hints if you need them. Plus a 2-question quiz.