Database concepts

Foundation

A database stores masses of data in order: tables split into records (rows) and fields (columns); the primary key identifies each record uniquely (student number, not name). Relational databases link tables; huge, multi-user, error-proof data needs a database, small personal maths a spreadsheet.

For:Secondary 3 Information & Communication Technology · Unit:Databases · Lesson 5 of 13 in the learning path

After this lesson, you can:
  • A database stores masses of data in order; the DBMS is the software managing it.
  • Tables: rows are records (one individual), columns are fields (one attribute).
  • The primary key identifies each record uniquely: unrepeatable, never empty, never changing — the student number, not the name.
文體:原理講解課有聲朗讀

文體小知識:原理講解課先講清楚概念和規則,再用實例演示,令抽象的設計方法變得具體易明。

資訊及通訊科技Information & Communication Technology

§Text Passage

1A database is a system that stores large amounts of data in an organised way, with a database management system (DBMS) handling access. At its core is the table: shaped like a spreadsheet worksheet, where each row is a record (all the data of one student) and each column is a field (such as name, class, score).

2Every table needs a primary key: a field that never repeats and is never empty, uniquely identifying each record — student numbers like 2023001, 2023002. Could the name be the primary key? No — a class can hold two Marys; only the student number identifies reliably. A relational database goes further: several tables link through shared fields — a scores table stores only the student number and joins back to the students table for the name.

3Compared with spreadsheets: spreadsheets suit individuals handling tens to hundreds of rows with calculations and charts; databases suit tens of thousands to millions of rows, many users reading and writing at once, fast searching and protection against wrong input. A school library catalogue of hundreds of thousands of books, or a citywide student record system, must use a database.

4Databases are everywhere in daily life: every Octopus journey, the hospital authority's booking system, an online shop's orders and stock — all run on databases. The standard language for talking to databases is SQL (Structured Query Language) — the next lessons use it to query data.

1Summary 重點摘要

A database stores masses of data in order: tables split into records (rows) and fields (columns); the primary key identifies each record uniquely (student number, not name). Relational databases link tables; huge, multi-user, error-proof data needs a database, small personal maths a spreadsheet.

2Vocabulary cards Vocabulary

D
Database資料庫

A system storing and managing large amounts of data in an organised way for searching, updating and error prevention.

T
Table資料表

The two-dimensional structure holding one kind of data, made of rows (records) and columns (fields).

R
Record記錄

One row of a table — all the data of a single individual, e.g. one student.

F
Field欄位

One column of a table — a single attribute of the data, e.g. name, class.

P
Primary key主鍵

The field uniquely identifying each record — never repeated, never empty, e.g. student number.

R
Relational database關聯式資料庫

A database of tables linked by shared fields, e.g. a scores table joining the students table by student number.

D
DBMS資料庫管理系統

The software managing a database — access, permissions and searching — e.g. MySQL, SQLite.

Q
Query查詢

A request made to a database, e.g. 'list all students in 3A', usually written in SQL.

D
Data redundancy資料冗餘

The same data stored in several places, which easily causes inconsistency after updates.

3Step by step Steps

  1. Meet a students tableThe heart of a database is the table, shaped much like a spreadsheet. Take a students table: it has three fields — student number, name and class; the header row lists the field names, and every row below is one record, e.g. (2023001, Mary, 3A), (2023002, John, 3B), (2023003, Peter, 3A). Remember the rule: the header holds the fields, and each row is one student's complete data. Reading a table's structure is the first step of learning databases.
  2. Telling records from fieldsRecords and fields are easily confused. In the students table above, the row '(2023002, John, 3B)' is one record — all the data of one student; the vertical column 'class' is one field — the same kind of data for every student. Mnemonic: rows are individuals, columns are attributes; one row per student, one column per data item. Exams often show a table and ask whether a marked part is a record or a field: ask whether it is a 'person' or a 'kind of data', and the answer is clear.
  3. Choosing a primary keyThe primary key is the field that uniquely identifies each record. Suppose the table holds two students both named Mary, with student numbers 2023001 and 2023004: identifying by name mistakes one for the other; by number is always right. A primary key has three conditions: never repeated, never empty, and ideally never changing. Names repeat and phone numbers change, so neither suits; a student number, assigned once by the school, is ideal. Every table must have a primary key — a guaranteed exam point.
  4. Linking tables in a relational databaseA relational database splits data across several tables joined by shared fields. For example, the scores table stores only (student_id 2023001, Maths, 85) with no name kept; to show the name, the database uses 2023001 to look up 'Mary' in the students table. The two tables join by student number, so names are never duplicated and redundancy is avoided: a name change is made in one place, and every score record follows automatically. This consistency is the great strength of the relational design.
  5. Database vs spreadsheetSpreadsheets and databases each have their strengths. Analysing one class of 40 scores, Excel finishes in ten minutes; but 400,000 students citywide, hundreds of teachers entering at once, and the need to block wrong values like '3Z' in the class column call for a database, which excels at concurrent access, fast searching of vast data and enforcing integrity rules. A simple rule: little data, single user — spreadsheet; much data, many users, error-proofing needed — database.
  6. Data integrity rulesA database can attach rules to every field to keep bad data out: scores must be numbers from 0 to 100; classes must be 3A to 3E; student numbers cannot be left empty. Any input breaking a rule is rejected, stopping junk data at the source. Spreadsheets rely on user discipline, and once a wrong value is in, it hides well. When exams ask 'why does the school system use a database instead of Excel', the answer should cite integrity rules, concurrent access and large volumes.
  7. Imagine a queryQuerying is the database's strength. A teacher wants '3A students scoring 80 or above in Maths': in a spreadsheet it takes several manual filter steps; in a database one SQL line does it — SELECT name FROM students WHERE class = '3A' AND score >= 80. The sentence means 'pick the names from the students table where the class is 3A and the score is at least 80'. The next lesson teaches SQL word by word; for now, remember that SQL is the standard language for talking to databases.

4Diagrams Diagrams

資料庫概念:有規律嘅超級表格 Database學號姓名班別2026001小明3A2026002小美3B2026003小剛3A欄位(直行)= 一種資料 · 記錄(橫行)= 一個對象嘅完整資料好處:大量資料有條理存放、快速搜尋、多人同時用都唔會亂生活例子:學校名冊、圖書館系統、網店訂單——全部行資料庫
Fig. 1: Database basics

5Worked example Example

Example: design a 'loans table' for the school library — list suitable fields, name the primary key, and show how it relates to other tables.

  1. Step one, list the needed fields: loan_id, student_id, book_id, borrow_date, return_date — one field for each item of data to keep.
  2. Step two, pick the primary key: loan_id is unique per loan, never repeated and never empty; student_id and book_id both repeat — one borrower takes many books, one book is borrowed by many — so neither can be the key.
  3. Step three, set the relations: student_id joins the students table for the borrower's name; book_id joins the books table for the title; the loans table never stores names or titles itself, avoiding redundancy.
  4. Step four, add integrity rules: borrow_date cannot be empty; return_date stays empty while the book is out and, once filled, must not be earlier than borrow_date; any input breaking a rule is rejected.
  5. Answer: The loans table has fields loan_id (primary key), student_id, book_id, borrow_date and return_date; the primary key is loan_id because only it never repeats and never stays empty; the table joins the students table by student_id and the books table by book_id, storing no names or titles itself; integrity rules guard against wrong input, and the design is complete.

6Common mistakes Mistakes

✗ Using the student's name as the primary key feels most natural.
✓ Names repeat (two Marys) and change (legal renames); a primary key needs a never-repeating number like the student ID.
✗ Records are columns and fields are rows.
✓ Reversed: a record is a row (all data of one individual); a field is a column (one attribute).
✗ Databases and spreadsheets are about the same — either will do.
✓ Dozens of personal rows suit a spreadsheet; hundreds of thousands of rows, many users at once and error-proofing demand a database.
✗ A database can hold only one table.
✓ A relational database is exactly many tables joined by shared fields, cutting duplicated storage.
✗ Storing the same data several times is harmless and handy.
✓ Redundancy causes real trouble: after a student changes class, one missed copy among three tables leaves data inconsistent; store names and titles once and look them up by relation.

7Quick check Quick check

Q1In a database table, what are a row and a column called?

Q2Which suits a students table's primary key best? A. name B. student number C. class

Q3Why does a scores table store the student number but not the name?

Q4Which tool suits analysing one class of 40 scores, and which suits a citywide system of 400,000 students entered by many users at once?

Q5'The score field accepts only numbers from 0 to 100' — which database mechanism is this?

8Recap Recap

  • A database stores masses of data in order; the DBMS is the software managing it.
  • Tables: rows are records (one individual), columns are fields (one attribute).
  • The primary key identifies each record uniquely: unrepeatable, never empty, never changing — the student number, not the name.
  • Relational databases join tables on shared fields, avoiding duplicate storage of the same data.
  • Small personal maths: a spreadsheet; huge, multi-user, error-proof data: a database.

Other subjects in this grade

Same subject, other grades