×

sql · level 1 · unit 7 · lesson 3

  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

gives every row its own number.

Two pets could both be called Rex. To tell rows apart, give each one an : a number no other row has, like a cloakroom ticket.

id INTEGER PRIMARY KEY makes that column the id. Leave it out of your INSERT and the database fills it in for you, counting 1, 2, 3.

Two rows can never share an id. Try it and you get UNIQUE constraint failed. So WHERE id = 2 always finds exactly one row.

CREATE TABLE members (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO members (name) VALUES ('Rex'), ('Rex'), ('Luna');
SELECT * FROM members;

An id is the safest thing to put in the WHERE of an UPDATE or DELETE.