An unnormalized table stores orders:
ORDERS(OrderID, OrderDate, CustomerID, CustomerName, CustomerCity, {ProductID, ProductName, UnitPrice, Quantity})
The items in braces repeat for each product on the order. Construct a database in third normal form (3NF) from this table. In your answer, identify the problem removed at each stage (1NF, 2NF, 3NF) and give the final relations with primary keys marked (PK) and foreign keys marked (FK). [6]
- 1NF: the repeating group (product details) must be removed so every attribute is atomic(1)
- 1NF relation has a composite key (OrderID, ProductID) (allow 1NF done by moving the repeating group to a separate table, e.g. OrderItem(OrderID, ProductID, ProductName, UnitPrice, Quantity), keyed on (OrderID, ProductID))(1)
- 2NF: ProductName and UnitPrice depend only on ProductID, and OrderDate, CustomerID, CustomerName, CustomerCity only on OrderID: partial (partial-key) dependencies on the composite key (if the repeating group was split off at 1NF, identifying the ProductID partial dependency alone is enough)(1)
- Partial dependencies removed to separate tables (Product, Orders, OrderLine)(1)
- 3NF: CustomerName and CustomerCity depend on CustomerID, not directly on OrderID (transitive dependency), so move to Customer(1)
- Final: Customer(CustomerID PK, CustomerName, CustomerCity); Product(ProductID PK, ProductName, UnitPrice); Orders(OrderID PK, OrderDate, CustomerID FK); OrderLine(OrderID PK/FK, ProductID PK/FK, Quantity). Allow different table names; allow other key notation (e.g. underline, asterisk) if clear; allow a price-at-sale field in OrderLine if justified(1)
- Answer: Customer, Product, Orders, OrderLine (see mark scheme)
- Examiner tip: Name the type of dependency (partial or transitive) as well as the attribute involved.