☰ خطة العام · تكنولوجيا المعلومات والاتصالات (بالإنجليزية)

Databases

الأسبوع 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
MemberIDNameClass
M1Hana1A
M2Omar1B
M3Layla1A
M4Karim1C
Worked examples
Loans
LoanIDMemberIDBookID
L1M1B2
L2M2B3
L3M1B3
L4M3B1
L5M4B2
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
BookIDTitleTopic
B1The Little BoatStory
B2Maps and StarsScience
B3Desert AnimalsScience
B4Cooking at HomeHobby
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?
2
Why must a primary key differ in every row?
3
Which database model links separate tables by a shared field?
4
Name one problem of keeping the same data in many separate lists.