الأسبوع 8 · الوحدة ٩ «قواعد البيانات»: لماذا نستخدم قاعدة بيانات، الجداول والسجلات والحقول، نماذج القواعد، العمليات العلائقية، نظم المعلومات · 3 دروس
1
Why a database beats a pile of lists
ICT Secondary 1 Term 1, Chapter 9: pp. 111–122
GoalExplain why a database is better than separate lists, and name rows, columns and keys.
New words
record · one row of a table: all the facts about one thingfield · one column of a table: one kind of factprimary key · a field whose value is different in every rowrelational database · tables linked by a field they share
Explanation
Imagine a school library club that keeps one list of borrowers on paper, another list of books, and another of fines. The same member’s name and class are copied into every list. This causes problems: the same fact can be written differently in two lists (inconsistency: the same fact is not the same everywhere), a change must be made many times, and mistakes creep in (the data stops being correct and valid, which is a loss of integrity). A database fixes this by keeping data in tables with a fixed structure. A table has rows, called records, and columns, called fields. A primary key is a field with a different value in every row, such as MemberID, so that a record can be found without doubt. Names are not good keys because two members may share a name. There are several database models: hierarchical (a tree: each item has one parent), network (items can have many links) and relational (separate tables linked by a field they share). The relational model is the most common. A database management system (DBMS) is the program that stores the data, controls who may read or change it, and keeps it safe. In a relational database each fact is stored once, in the right table, and other tables refer to it by its key.
Members
MemberID
Name
Class
M1
Hana
1A
M2
Omar
1B
M3
Layla
1A
M4
Karim
1C
Worked examples
Loans
LoanID
MemberID
BookID
L1
M1
B2
L2
M2
B3
L3
M1
B3
L4
M3
B1
L5
M4
B2
The three tables of the club are Members, Books and Loans. In Members the key is MemberID. The Loans table refers to a member and a book only by their keys (M1, B2), so a member’s name is stored once. If Hana changes class, only one cell changes.
Books
BookID
Title
Topic
B1
The Little Boat
Story
B2
Maps and Stars
Science
B3
Desert Animals
Science
B4
Cooking at Home
Hobby
Why is Name a poor primary key? If two members were both called Omar, the name would not point to one row. MemberID is better: M2 can belong to only one member. The picture shows the books table, with BookID as the key.
Class activity
On paper, design two tables for a class sports day: one for pupils (with a key) and one for events. Then decide what a third table, Entries, needs so that it can say who takes part in which event without repeating names.
Practice
1
What is a record, and what is a field?
A record is a row (all facts about one thing); a field is a column (one kind of fact).
2
Why must a primary key differ in every row?
So that one record can be found without doubt.
3
Which database model links separate tables by a shared field?
The relational model.
4
Name one problem of keeping the same data in many separate lists.
For example: the same fact can differ between lists, and one change must be made many times.