typestar

CREATE TABLE in SQL

A table definition: columns, types and the constraints that guard them.

CREATE TABLE orders (
    id INTEGER PRIMARY KEY,
    customer_id INTEGER NOT NULL,
    total REAL NOT NULL DEFAULT 0,
    status TEXT NOT NULL DEFAULT 'pending',
    placed_at TIMESTAMP NOT NULL,
    CHECK (total >= 0)
);

How it works

  1. PRIMARY KEY identifies a row uniquely.
  2. NOT NULL and DEFAULT decide what a missing value means.
  3. CHECK refuses rows that break a rule at write time.

Keywords and builtins used here

The run, in numbers

Lines
8
Characters to type
198
Tokens
42
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 32 seconds.

Type this snippet

Step 1 of 8 in Tables & rows, step 14 of 23 in Language basics.

← Previous Next →