Database concepts and the relational model
A database is an organised collection of related data; a relational database stores it in linked tables joined by keys.
The data hierarchy
File-based approach vs database approach
A relational table: Customer
| CustomerID (PK) | Name | City | Credit limit (Rs.) |
|---|---|---|---|
| C001 | Nimal Perera | Kandy | 100,000 |
| C002 | Fathima Rizwan | Colombo | 250,000 |
| C003 | Kumar Rajan | Jaffna | 75,000 |
A linked table: Order
| OrderID (PK) | Date | CustomerID (FK) | Amount (Rs.) |
|---|---|---|---|
| O101 | 2026-03-02 | C002 | 45,000 |
| O102 | 2026-03-02 | C001 | 12,500 |
| O103 | 2026-03-05 | C002 | 8,750 |
How the keys link the tables
CustomerID is the primary key of Customer: no two customers share it. The same field in Order is a foreign key: it points back to the customer who placed each order. So the database can tell that Fathima Rizwan (C002) placed orders O101 and O103, worth 45,000 + 8,750 = Rs. 53,750, without storing her name and city again in every order.
Key terms
| Term | Meaning |
|---|---|
| Relation (table) | Data about one subject, in rows and columns |
| Record (row, tuple) | All the data about one item, e.g. one customer |
| Field (column, attribute) | One kind of data, e.g. City |
| Primary key | Field that uniquely identifies each record |
| Foreign key | Field in one table that matches the primary key of another |
| Composite key | Two or more fields that together identify a record |
| Candidate key | Any field that could serve as the primary key |
Advantages and disadvantages of databases
A Sri Lankan supermarket chain or telco keeps customers, products and transactions in linked tables. One customer ID (the primary key) appears as a foreign key in every bill, so a loyalty card shows points earned in any branch.
Short answer: “What is a primary key?” A field (or fields) whose value uniquely identifies each record in a table, e.g. CustomerID.
Structured question: “Distinguish between the file-based approach and the database approach.” Files: separate departmental files, redundancy, inconsistency, poor sharing. Database: one integrated store under a DBMS, less redundancy, consistency, sharing and security.
Essay: “Explain the relational database concept with an example.” Explain the data hierarchy, tables, records and fields, primary and foreign keys, show two linked tables, and give advantages over files.
Row = record, column = field, table = relation. The PK is the unique ID in its own table; the FK is the same ID borrowed by another table to link them.