| Lesson 7 | One-to-many Relationships |
| Objective | Identify one-to-many relationships in an ERD and map them to tables. |
A one-to-many (1:N) relationship exists when one instance of entity A can be related to zero, one, or many instances of entity B, while each instance of B is related to at most one instance of A. This lesson shows how to recognize 1:N in an ER diagram, how to confirm it from business rules, and how to implement it with keys.
CUSTOMER(CustomerID) ⟶ oneORDER(OrderID, CustomerID FK→Customer.CustomerID) ⟶ many| on the “one” side and a crow’s foot << on the “many” side. Optionality is shown with a small circle O.
DEPARTMENT |──────────<< EMPLOYEE
|=mandatory, O=optional.
CUSTOMER (1) ───── <──── (0..*) ORDERRead as: one Customer can have zero or many Orders; each Order has exactly one Customer.
| Indicator | Meaning |
|---|---|
| Foreign Key | FK resides on the many-side; references one-side PK |
| Crow’s Foot | Three prongs at the many-side; bar/circle at the one-side |
| Cardinality | 1 to 0..*, or 1 to N |
| Business rule | One A can own/contain many B; each B belongs to one A |
Implement by placing the parent’s PK in the child as a FK. Add an index on the FK for join performance.
-- Parent (one)
CREATE TABLE Department (
DeptID INT PRIMARY KEY,
DeptName VARCHAR(100) NOT NULL
);
-- Child (many)
CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
EmpName VARCHAR(100) NOT NULL,
DeptID INT NOT NULL,
CONSTRAINT fk_employee_dept
FOREIGN KEY (DeptID) REFERENCES Department(DeptID)
ON DELETE RESTRICT
ON UPDATE CASCADE
);
-- Helpful for joins:
CREATE INDEX ix_employee_deptid ON Employee(DeptID);
DeptID to be NULL (0..*).DeptID NOT NULL (1..*).RESTRICT (safest), or CASCADE if child rows should be removed with the parent.VendorID.
A many-to-one (N:1) view is the same relationship read from the other side. Implementation does not change—the FK remains on the many side.
DeptID from DEPARTMENT (one).
Order1, Order2, Order3). Use rows, not extra columns.When you have two entities A and B, ask:
If the answers are “many” for #1 and “one (or none)” for #2, you’re looking at a 1:N relationship.
Most relational designs consist primarily of one-to-many relationships. In the next lesson you’ll learn how many-to-many relationships are converted into two 1:N relationships via an associative (junction) entity.