×

sql · level 2 · unit 6 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

fills in a value whenever you leave a column out.

In Level 1, a column you left out of an INSERT became NULL. Often there is a better start. A new order is 'open', and a new player has 0 points.

Write DEFAULT and a value after the column's type, like status TEXT DEFAULT 'open'. Leave status out of an INSERT and the database writes 'open' for you.

Give the column a value yourself and the default steps aside. It only ever fills a gap.

CREATE TABLE orders (
  id INTEGER PRIMARY KEY,
  item TEXT NOT NULL,
  status TEXT DEFAULT 'open'
);
INSERT INTO orders (item) VALUES ('Teapot');
INSERT INTO orders (item, status) VALUES ('Mug', 'sent');
SELECT * FROM orders;

Writing NULL on purpose still stores NULL. Add NOT NULL too if the box must never be empty.