Computer Science

Senior High

NotesFree

The Relational Database Model: Tables, Keys and Relationships

Topic: Y2-3 Relational database model

How relational databases organise data, explained step by step: why they matter for e-commerce, tables, fields and records, entities and attributes, one-to-many and many-to-many relationships, primary, foreign and composite keys; creating a database and tables in MySQL with XAMPP and phpMyAdmin, data types, and querying.

View resource Free to join

What's inside

Imagine a shop that writes every sale on paper: the customer's name, phone number, address and what they bought. A loyal customer who buys fifty times has their address written fifty times, and if they move house, all fifty entries are wrong. A relational database fixes this by storing each fact once, in the right table, and linking the tables together. This note explains how.

SUMMARIZED NOTES

  • Year 1: No content on databases in Year 1.

  • Year 2: What a relational database is and why it matters, tables, fields and records, entities and attributes, relationships, and primary, foreign and composite keys.

  • Year 3: Creating a database and tables in MySQL using XAMPP and phpMyAdmin, choosing data types, adding data, and querying it.

Year 2 Notes: How relational databases organise data

What a relational database is

A relational database organizes data into tables of rows and columns, like spreadsheets and the tables are connected ("related") by shared values. That makes data easy to manage and retrieve.

Why it matters for an online shop

  • It manages large amounts of data (products, customers, orders) in separate, connected tables without repeating anything. When you order on Jumia, the database links you to your order and updates the stock automatically.

  • It keeps data accurate and avoids redundancy. A customer's address is stored once, in the Customers table, and linked to every order. Change it once, and it is correct everywhere.

  • It supports queries and analysis: finding products by name, category or price, viewing a customer's purchase history, or producing sales reports.

  • It works in real time, keeping the site quick and up to date even when many customers shop at once.

Tables, fields and records

A table (or relation) stores data about one kind of thing: a Products table, a Customers table, an Orders table, a Transactions table. Its columns, also called fields or attributes, are the kinds of detail stored (CustomerID, Name, Email). Its rows, also called records or tuples, each hold all the details about one item, such as one customer.

ProductID

ProductName

Price

Quantity

1

Wristwatch

GH₵ 373.30

4

2

Tecno Camon 30

GH₵ 3,494.80

1

3

Toshiba Laptop

GH₵ 5,536.00

1

An entity is anything we store data about: a product, a customer, an order. Its attributes are the details describing it: a Product has ProductID, Name, Description, Price and StockQuantity; a Customer has CustomerID, Name, Email, Address and PhoneNumber; an Order has OrderID, CustomerID, OrderDate and OrderTotal.

Open the full resource free with a TudHub account.

More on Relational database model

Other resources you can find on TudHub.

The Relational Database Model: Tables, Keys and Relationships (Computer Science) · TudHub