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
PRIMARY KEYidentifies a row uniquely.NOT NULLandDEFAULTdecide what a missing value means.CHECKrefuses rows that break a rule at write time.
Keywords and builtins used here
CHECKCREATEDEFAULTINTEGERKEYNOTNULLPRIMARYREALTABLETEXTTIMESTAMP
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.
Step 1 of 8 in Tables & rows, step 14 of 23 in Language basics.