basics04Chapter 4 of 6
ER diagrams
An entity relationship diagram, ER diagram for short, is the map of a database: every table a box, every link a line.
How to read it
- Each box is a table (an entity). Its name is at the top.
- Below it come the columns (attributes) with their types.
- PK marks the primary key, FK a foreign key.
- A line joins a foreign key to the primary key it points at. The ends of the line show the cardinality.
The Byte Shop
Click a line or its label to read it as a sentence.
byte-shop.db
Throughorders.customer_idcustomers.id
A customer has no, one or many orders; each order belongs to exactly one customer.
The hidden n:m
Customers and products have no line of their own. They are linked through orders: one customer, many orders, each with one product. That is the n:m from the last chapter, drawn the way a database stores it.