Databases & SQL
Lesson 1 of 4 9 min +70 XP

Tables, Rows & Keys

How relational databases organize data.

What you'll learn

  • Describe a table
  • Define a primary key
  • Explain a foreign key
The class attendance binder

A school binder has a page per class, each a table of rows (students) and columns (name, grade, ID). The ID column is the key — the unique thing that tells two students named Alex apart. Relational databases store data in exactly these keyed tables.

Data in rows and columns

A relational database stores data in tables. Each row is a record; each column is a field. A primary key is a column whose value uniquely identifies each row. A foreign key in one table points to the primary key of another, linking them.

students(id PK, name)
enrollments(id PK, student_id FK, course)
Lab · Pick the key
  1. In a students table with id, name, and email, which column best uniquely identifies a row?
  2. Decide why name is a poor choice.
  3. Name the column that links enrollments to students.

What you should see: id is the primary key (unique); names can repeat. student_id is the foreign key linking to students.

Knowledge Check

+20 XP / correct

1. A column that uniquely identifies each row is the…

2. In a relational database, a single record is a…