When a File Is No Longer Enough
Tables, Rows, Columns, and a Schema
SQLite gives the lending project a real database engine. We still need to decide how the facts are arranged inside its database. Riley’s email was copied because each CSV row tried to describe a member, an item, and a loan at the same time. A
Here are the current rows in the items table:
| id | name | category |
|---|---|---|
| 1 | Cordless drill | tools |
| 2 | Folding table | events |
| 3 | Projector | electronics |
Now find the projector in this table and read across its row. The three values belong to one item: its number is 3, its name is Projector, and its category is electronics.
A row holds one record. A column gives the same kind of category column, you get tools, events, and electronics.
Show the table’s schema
The rows above are the data stored right now. The table also has a design that says what each row can contain:
Schema for items
| Column | What belongs here |
|---|---|
id | a whole-number item ID |
name | text containing the item’s name |
category | text naming the group the item belongs to |
That design is the table’s schema. It gives the table its name and gives each column a name and purpose.
Suppose Projector is renamed Portable projector. Only one value in the current rows changes. The schema still has the same three columns.
Now suppose the catalog needs to record whether each item is in good condition column would change the schema because every item row would gain a new named place for that information.
Which action changes the schema of the items table?
Different facts, different tables
The finished lending database will give each kind of thing its own table:
| Table | One row describes |
|---|---|
members | one person who can borrow equipment |
items | one thing that can be borrowed |
loans | one occasion when a member borrows an item |
We will connect those tables later. For now, stay with items and imagine that someone asks, “What can people borrow?” The answer only needs the names, not every value in every row. In the next lesson, you will ask SQLite to return just the name column.