Keelmark Your record

Unit IV · Your data

Tables, rows and keys

Lesson 10 of 185 minSources checked Oct 17, 2026

A relational database stores data in tables. Keys and constraints are rules the database enforces for you, even when the code, or the AI that wrote it, forgets.

Tables, rows, columns

A table holds one kind of thing (users, orders); each row is one of them; each column is one field with a type (text, number, date). Queries read and change rows; most apps use SQL to do it, directly or through a library.

Keys

A primary key identifies each row uniquely, often a number called id. A foreign key says a value must match a row in another table, so an order cannot point at a customer who does not exist; deleting that customer then either fails or follows the rule you chose.

Constraints catch mistakes

A UNIQUE constraint stops two users signing up with the same email, even if both requests arrive at the same moment. NOT NULL makes a column required. A rule enforced by the database holds for every part of the app, not just the page that remembered to check.

Words to know

Table
a set of rows of one kind
Primary key
the column that identifies each row
Foreign key
a column that must match a row in another table
Constraint
a rule the database enforces on its data

Sources

  1. PostgreSQL documentation: Constraints
  2. PostgreSQL documentation: Table Basics

Checked October 17, 2026. Pages on other sites change; if a source no longer says what the lesson says, the source wins.

Lesson check

Two questions. Answer both correctly to pass this lesson. You can try as often as you like.

1What stops two accounts from having the same email, even when two sign-ups arrive at once?
2What does a foreign key do?