Skip to content · ⁨الانتقال إلى المحتوى⁩

Databases · ⁨قواعد البيانات⁩

A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩ · Topic 8 · ⁨الموضوع 8⁩

Video lesson for this topic · ⁨درس فيديو لهذا الموضوع⁩ Open the video page · ⁨افتح صفحة الفيديو⁩
17:18

قواعد البيانات والنموذج العلائقي

قبل قواعد البيانات، كان كل برنامج يحتفظ بملفات مسطحة خاصة به — ملف واحد لكل برنامج. تخيل متجرًا. برنامج المبيعات، وبرنامج الفواتير، وبرنامج الشحن…

English narration · English + 中文 subtitles burned in · ⁨سرد باللغة الإنجليزية · ترجمة مدمجة بالإنجليزية + الصينية⁩

8.1

File-based storage and its limits · ⁨التخزين القائم على الملفات وقيودها⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding of the limitations of using a file-based approach for the storage and retrieval of data
Describe the features of a relational database that address the limitations of a file-based approach
Show understanding of and use the terminology associated with a relational database model Including entity, table, record, field, tuple, attribute, primary key, candidate key, secondary key, foreign key, relationship (one-to-many, one-to-one, many-to-many), referential integrity, indexing
Use an entity-relationship (E-R) diagram to document a database design
Show understanding of the normalisation process First Normal Form (1NF), Second Normal Form (2NF) and Third Normal Form (3NF)
Explain why a given set of database tables are, or are not, in 3NF
Produce a normalised database design for a description of a database, a given set of data, or a given set of tables
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
إظهار فهم قيود استخدام نهج الملفات لتخزين واسترجاع البيانات
وصف ميزات قاعدة البيانات العلائقية التي تعالج قيود نهج الملفات
إظهار فهم واستخدام المصطلحات المرتبطة بنموذج قاعدة البيانات العلائقية بما في ذلك الكيان، الجدول، السجل، الحقل، العنصر، الخاصية، المفتاح الأساسي، المفتاح المرشح، المفتاح الثانوي، المفتاح الأجنبي، العلاقة (واحد إلى متعدد، واحد إلى واحد، متعدد إلى متعدد)، النزاهة المرجعية، الفهرسة
استخدام مخطط الكائن-العلاقة (E-R) لتوثيق تصميم قاعدة البيانات
إظهار فهم عملية التطبيع الشكل الأولي المطبق (1NF)، الشكل الثاني المطبق (2NF) والشكل الثالث المطبق (3NF)
شرح سبب كون مجموعة معينة من جداول قاعدة البيانات مطبقة بشكل 3NF أو غير مطبقة
إعداد تصميم قاعدة بيانات مطبقة بناءً على وصف لقاعدة بيانات، أو مجموعة معطيات محددة، أو مجموعة جداول محددة

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

Before databases, programs stored data in flat files 平面文件 — usually one file per program. This is fine for small data but breaks down at scale.

Limitations

  • data redundancy 数据冗余 — the same data (a customer's address) is held in several files, one per program, so storage is wasted and every copy must be updated.
  • data inconsistency 数据不一致 — when one copy is updated and another is not, the files disagree and nobody knows which is right.
  • data dependence — each program is written for the exact layout of its files; change a field's length or add a field and every program that reads the file must be rewritten.
  • no shared access — a file is locked while one program uses it, so users cannot work on the data at the same time.
  • weak integrity 完整性 — no central rules stop an invalid value or a link to a customer who does not exist; weak security — access is per file, not per field; and queries across files need a new program each time.

A relational database 关系数据库 fixes these by storing data in tables managed by one piece of software (the DBMS) that all programs use.

Why a relational database is better — the three-mark answer. Each item of data is stored once, in one table, and tables are linked by keys, so there is no redundancy and no inconsistency; the data is independent of the programs, which ask the DBMS for what they need and are unaffected when the structure changes; and the DBMS enforces integrity rules, controls access per user and per field, allows many users at once, and answers any query without a new program being written.

Worked example. A repair shop stores its customers, devices and repair jobs using a file-based approach, one file per program. Give three problems this causes, and describe how a relational database would remove them.

The customer's name and phone number are stored in the repairs file and the invoices file (redundancy); when a customer changes number, one file is updated and the other is not (inconsistency); and when the shop wants a new report — repairs per technician — a new program has to be written to read the files (no ad-hoc queries). In a relational database the customer is stored once in a CUSTOMER table and referred to by CustomerID from the REPAIR table, so a change is made once and is seen everywhere; the report is a single SQL query.

العربية

قبل ظهور قواعد البيانات، كانت البرامج تخزن البيانات في ملفات مسطحة — عادةً ملف واحد لكل برنامج. هذا مقبول للبيانات الصغيرة لكنه يفشل عند التوسع.

يد تبحث في خزانة ملفات ببطاقات
يحتفظ التخزين القائم على الملفات بالبيانات في ملفات منفصلة، مثل الأوراق في خزانة الملفات — صعب البحث عنه وسهل تكراره

القيود

  • تكرار البيانات — نفس البيانات (مثل عنوان العميل) محفوظة في عدة ملفات، ملف لكل برنامج، مما يهدر مساحة التخزين ويجب تحديث كل نسخة.
  • عدم اتساق البيانات — عندما يتم تحديث نسخة وعدم تحديث أخرى، تتعارض الملفات ولا أحد يعرف أيهما صحيح.
  • اعتماد البيانات — كل برنامج مكتوب لتنسيق ملفات محدد بدقة؛ تغيير طول حقل أو إضافة حقل يستلزم إعادة كتابة كل برنامج يقرأ الملف.
  • عدم إمكانية الوصول المشترك — يُقفل الملف أثناء استخدام برنامج له، لذا لا يمكن للمستخدمين العمل على البيانات في نفس الوقت.
  • ضعف النزاهة — لا توجد قواعد مركزية تمنع إدخال قيمة غير صالحة أو ارتباط بعميل غير موجود؛ ضعف الأمن السيبراني — الوصول يكون للملف وليس للحقل؛ والاستعلامات عبر الملفات تتطلب برنامجاً جديداً في كل مرة.
برامج الرواتب والمبيعات يرتبط كل منهما بملف بيانات منفصل خاص به، لذا يتم تخزين حقل رقم الموظف مرتين
النهج القائم على الملفات: يحتفظ كل برنامج بملفاته الخاصة

قاعدة البيانات العلائقية تحل هذه المشاكل بتخزين البيانات في جداول يديرها برنامج واحد (نظام إدارة قواعد البيانات DBMS) تستخدمه جميع البرامج.

نظام إدارة قاعدة بيانات واحد يحتوي على تصاميم الجداول وقواعد التحقق وحقوق الوصول والبيانات، مع قاعدة بيانات مشتركة واحدة تستخدمها تطبيقات الرواتب والمبيعات
نهج قاعدة البيانات: نظام إدارة قاعدة بيانات واحد يخدم جميع البرامج

لماذا قاعدة البيانات العلائقية أفضل — إجابة ثلاث درجات. تُخزن كل عنصر بيانات مرة واحدة، في جدول واحد، وتُربط الجداول بالمفاتيح، لذا لا يوجد تكرار عدم اتساق؛ البيانات مستقلة عن البرامج، التي تطلب من نظام إدارة قواعد البيانات ما تحتاجه ولا تتأثر بتغير البنية؛ ونظام إدارة قواعد البيانات يفرض قواعد النزاهة، ويتحكم في الوصول لكل مستخدم وكل حقل، ويسمح لـعدد كبير من المستخدمين في آنٍ واحد، ويجيب على أي استعلام دون الحاجة لكتابة برنامج جديد.

مثال محلول. يخزن ورشة إصلاح عملائها وأجهزتها ومهام الإصلاح باستخدام نهج قائم على الملفات، ملف لكل برنامج. اذكر ثلاث مشاكل يسببها ذلك، واصف كيف ستزيل قاعدة البيانات العلائقية تلك المشاكل.

اسم العميل ورقم الهاتف محفوظان في ملف الإصلاحات و ملف الفواتير (تكرار)؛ عندما يغير العميل رقمه، يتم تحديث ملف وعدم تحديث الآخر (عدم اتساق)؛ وعندما تريد الورشة تقريراً جديداً — الإصلاحات حسب الفني — يجب كتابة برنامج جديد لقراءة الملفات (عدم وجود استعلامات فورية). في قاعدة البيانات العلائقية، يُخزن العميل مرة واحدة في جدول العملاء ويُشار إليه برقم العميل من جدول الإصلاحات، لذا يتم التغيير مرة واحدة ويظهر في كل مكان؛ والتقرير عبارة عن استعلام SQL واحد.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
DBMS/ˌdiː biː em ˈes/ نظام إدارة قواعد البيانات
SQL/ˌes kjuː ˈel/ SQL
entity/ˈentɪti/ كائن
record/ˈrekɔːd/ سجل
tuple/ˈtuːpl/ زوجة
attribute/ˈætrɪbjuːt/ سمة
8.1

Relational model — terms · ⁨النموذج العلائقي — المصطلحات⁩

English
  • table 表 (relation) — a grid of rows and columns; one table per type of entity 实体 (e.g. CUSTOMER).
  • record 记录 (row, also called a tuple 元组) — one row; one instance of the entity.
  • field 字段 (column, also called an attribute 属性) — one column; one piece of information about each record.
  • primary key 主键 — a field (or fields) that uniquely identifies each record; never null or duplicated.
  • foreign key 外键 — a field whose value matches the primary key of another table, linking the two.
  • composite key 复合键 — a primary key made of two or more fields together.
  • candidate key 候选键 — any field(s) that could be the primary key.
  • secondary key 次键 — a non-primary field that is indexed for fast searching.
  • indexing 索引 — building an index on a field so look-ups and joins run faster.
  • referential integrity 参照完整性 — every foreign-key value must match an existing primary key (no orphan records).

A table is written in shorthand with the primary key underlined and foreign keys noted:

Worked example. State what is meant by entity, primary key and referential integrity in a relational database, and complete the term ↔ description table for tuple and attribute.

An entity is something about which data is stored — a person, object or event — which becomes one table. A primary key is the attribute (or combination of attributes) that uniquely identifies each record in a table. Referential integrity means that every foreign-key value must match the value of a primary key in the table it refers to, so a record cannot refer to one that does not exist. A tuple is one row of a table (one record); an attribute is one column (one field). Learn the pairs: table/relation, record/tuple, field/attribute.

العربية
  • جدول (علاقة) — شبكة من الصفوف والأعمدة؛ جدول واحد لكل نوع من الكائنات (مثل CUSTOMER).
  • سجل (صف، يُسمى أيضاً ثابتة) — صف واحد؛ حالة واحدة للكائن.
  • حقل (عمود، يُسمى أيضاً صفة) — عمود واحد؛ قطعة معلومات واحدة عن كل سجل.
  • المفتاح الأساسي — حقل (أو حقول) يحدد بشكل فريد كل سجل؛ لا يمكن أن يكون فارغاً أو مكرراً.
  • المفتاح الأجنبي — حقل قيمته تطابق المفتاح الأساسي لجدول آخر، رابطة بين الاثنين.
  • المفتاح المركب — مفتاح أساسي يتكون من حقلين أو أكثر معاً.
  • المفتاح المرشح — أي حقل (أو حقول) يمكن أن يكون المفتاح الأساسي.
  • المفتاح الثانوي — حقل غير أساسي تم إنشاء فهرس عليه للبحث السريع.
  • الفهرسة — بناء فهرس على حقل使得 عمليات الاستعلام والروابط أسرع.
  • النزاهة المرجعية — يجب أن تطابق قيمة المفتاح الأجنبي مفتاحاً أساسياً موجوداً (لا سجلات يتيمه).

يُكتب الجدول بصيغة مختصرة مع وضع خط تحت المفتاح الأساسي وتوثيق المفاتيح الأجنبية:

CUSTOMER(CustomerID, Name, Phone)
ORDER(OrderID, CustomerID, OrderDate)   -- CustomerID is FK → CUSTOMER
جدولين مربوطين بمفتاح أجنبي: جدول العملاء يحتوي على المفتاح الأساسي رقم العميل؛ جدول الطلبات يحتوي على مفتاحه الأساسي رقم الطلب بالإضافة إلى مفتاح أجنبي رقم العميل الذي تطابق قيمته رقم عميل في جدول العملاء
المفتاح الأجنبي يربط جدولين: رقم عميل في الطلب يطابق المفتاح الأساسي رقم عميل في جدول العملاء

مثال محلول. عرّف ما يعنيه كائن، المفتاح الأساسي والنزاهة المرجعية في قاعدة بيانات علائقية، وأكمل جدول مصطلح ↔ وصف لـثابتة وصفة.

الكائن هو شيء تُخزن حوله البيانات — شخص، كائن أو حدث — والذي يصبح جدولاً واحداً. المفتاح الأساسي هو الصفة (أو مجموعة الصفات) التي تحدد بشكل فريد كل سجل في الجدول. النزاهة المرجعية تعني أن كل قيمة لمفتاح أجنبي يجب أن تطابق قيمة مفتاح أساسي في الجدول الذي تشير إليه، sehingga لا يمكن للسجل الإشارة إلى سجل غير موجود. الثابتة هي صف واحد من جدول (سجل واحد)؛ الصفة هي عمود واحد (حقل واحد). احفظ الأزواج: جدول/علاقة، سجل/ثابتة، حقل/صفة.

Explore · ⁨استكشف⁩

Read a relational table with SELECT · ⁨اقرأ جدول علائقي باستخدام SELECT⁩

A relational table is just rows (records) and columns (fields). WHERE keeps the rows that match a condition; SELECT then keeps only the columns you asked for. · ⁨الجدول العلائقي هو مجرد صفوف (سجلات) وأعمدة (حقول). يحفظ WHERE الصفوف التي تطابق شرطًا؛ ثم يحفظ SELECT فقط الأعمدة التي طلبتها.⁩

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
table/ˈteɪbl/ جدول
8.1

Entity-relationship (E-R) diagrams · ⁨مخططات الكائن-العلاقة (E-R)⁩

English

An entity-relationship diagram 实体关系图 shows the structure: each entity is a rectangle, each relationship a line, with the cardinality 基数 marked at each end:

  • one-to-one (1:1).
  • one-to-many 一对多 (1:M) — each Customer has many Orders; each Order has one Customer.
  • many-to-many (M:N) — Students take many Courses, and Courses have many Students.

A many-to-many relationship cannot be stored directly. Break it into two one-to-many relationships through a link table 连接表 holding the two foreign keys:

Drawing the E-R diagram for a given set of tables. Each table becomes an entity. A relationship exists wherever one table holds a foreign key to another; it runs from the table holding the foreign key (the many end) to the table whose primary key it is (the one end). A table with two foreign keys and no other identity is usually a link table resolving a many-to-many relationship. Label each line with the relationship type.

Worked example. A repair shop has the tables CUSTOMER(CustomerID, Name, Phone), DEVICE(DeviceID, CustomerID, Type, Model), TECHNICIAN(TechnicianID, Name) and REPAIR(RepairID, DeviceID, TechnicianID, RepairDate, Cost). Identify the relationships and their types.

DEVICE holds CustomerID, so CUSTOMER–DEVICE is one-to-many (one customer, many devices). REPAIR holds DeviceID, so DEVICE–REPAIR is one-to-many; it also holds TechnicianID, so TECHNICIAN–REPAIR is one-to-many. There is no direct CUSTOMER–REPAIR line: the link runs through DEVICE. Three lines, three crow's feet, all at the REPAIR or DEVICE ends.

العربية

مخطط الكائن-العلاقة يوضح البنية: كل كائن مستطيل، كل علاقة خط، مع تحديد الكاردينالية عند كل طرف:

  • واحد لواحد (1:1).
  • واحد إلى متعدد (1:M) — كل عميل له العديد من الطلبات؛ وكل طلب لعميل واحد.
  • متعدد إلى متعدد (M:N) — الطلاب يسجلون في دورات عديدة، والدورات تحتوي على طلاب متعددين.
مخطط K-E يحتوي على كيان الطالب وكيان الصف موصولين بخط علاقة، مع رمز "رجل النعام" للعديد في طرف الطالب وخط واحد في طرف الصف
مخطط K-E: صف واحد يحتوي على طلاب متعددين
رموز نهاية خط رجل النعام للواحد، والعديد، والواحد فقط، والصفر أو الواحد، والواحد أو العديد، والصفر أو العديد
رموز رجل النعام لتكرار العلاقة

لا يمكن تخزين علاقة متعدد إلى متعدد مباشرة. يتم تقسيمها إلى علاقتين واحد إلى متعدد عبر جدول ربط يحمل مفتاحي أجنبي:

ENROLMENT(StudentID, CourseID, EnrolmentDate)
علاقة متعدد إلى متعدد بين الطالب والدورة مخزنة كعلاقتي واحد إلى متعدد عبر جدول ربط التسجيل يحمل معرف الطالب ومعرف الدورة
جدول الربط يحول علاقة متعدد إلى متعدد إلى علاقتين واحد إلى متعدد

رسم مخطط K-E لمجموعة جداول معينة. كل جدول يصبح كيانًا. توجد علاقة حيثما يحمل جدول واحد مفتاحًا أجنبيًا لجداول أخرى؛ يمتد الخط من الجدول الذي يحمل المفتاح الأجنبي (طرف العديد) إلى الجدول الذي يمثل مفتاحه الأساسي (طرف الواحد). الجدول الذي يحتوي على مفتاحين أجنيين وبدون هوية أخرى هو عادةً جدول ربط يحول علاقة متعدد إلى متعدد. ضع تسمية لكل خط بنوع العلاقة.

مخطط K-E لقاعدة بيانات ورشة إصلاح بأربعة كيانيات: عميل واحد إلى متعدد جهاز، جهاز واحد إلى متعدد إصلاح وفني واحد إلى متعدد إصلاح، مع رموز رجل النعام والمفاتيح الأساسية والأجنبية الموضحة
رسم المخطط من الجداول: كل مفتاح أجنبي هو علاقة واحد إلى متعدد، مع طرف "العديد" عند الجدول الذي يحتويه

مثال محلول. تمتلك ورشة الإصلاح الجداول CUSTOMER(CustomerID, Name, Phone)، DEVICE(DeviceID, CustomerID, Type, Model)، TECHNICIAN(TechnicianID, Name) وREPAIR(RepairID, DeviceID, TechnicianID, RepairDate, Cost). حدد العلاقات وأنواعها.

DEVICE ينطبق على CustomerID، لذا فإن CUSTOMER–DEVICE واحد لمتعدد (عميل واحد، أجهزة متعددة). REPAIR ينطبق على DeviceID، لذا فإن DEVICE–REPAIR واحد لمتعدد؛ كما ينطبق على TechnicianID، لذا فإن TECHNICIAN–REPAIR واحد لمتعدد. لا يوجد خط مباشر بين CUSTOMER–REPAIR: يمتد الرابط عبر DEVICE. ثلاثة خطوط، ثلاث أقدام الغراب، جميعها في نهايات REPAIR أو DEVICE.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
cardinality/ˌkɑːdɪˈnælɪti/ الكاردينالية
one-to-many/wʌn tə ˈmeni/ واحد إلى متعدد
link table/lɪŋk ˈteɪbl/ جدول الروابط
8.1

Normalisation · ⁨التطبيع⁩

English

Normalisation 规范化 organises tables to cut redundancy and inconsistency, going through normal forms 范式 in order.

  • First normal form (1NF) — every field holds a single (atomic 原子) value, with no repeating groups, and a primary key.
  • Second normal form (2NF) — in 1NF, and every non-key field depends on the whole primary key (only matters for a composite key).
  • Third normal form (3NF) — in 2NF, and every non-key field depends only on the primary key, not on another non-key field (no transitive dependency 传递依赖).

A 3NF design stores each fact once, so insert/update/delete anomalies disappear. The trade-off is more tables and more joins. Aim for 3NF.

To produce a 3NF design: find the entities and their attributes; choose a primary key for each; split repeating/non-atomic fields (1NF); split fields depending on part of a composite key (2NF); split fields depending transitively on the key (3NF); add foreign keys for the relationships.

Worked example. The table ORDER(OrderID, CustomerID, CustomerName, ProductID, Quantity) has the composite primary key (OrderID, ProductID). Normalise it to 3NF. Test each non-key field against the key. Quantity depends on both OrderID and ProductID, which is fine. But CustomerID depends on OrderID alone - only part of the composite key. That is a partial dependency, so the table is not in 2NF. Split it into ORDER_LINE(OrderID, ProductID, Quantity) and ORDER(OrderID, CustomerID, CustomerName). Now test 3NF: in that new ORDER table, CustomerName depends on CustomerID, which is not the key - a transitive dependency. Split again: ORDER(OrderID, CustomerID) and CUSTOMER(CustomerID, CustomerName). Name the dependency that breaks each form (partial breaks 2NF, transitive breaks 3NF); "it has repeated data" describes the symptom and earns nothing.

The three questions to ask of any table. Is every cell a single value, with no repeating group? If not, it is not in 1NF. If the key is composite, does every non-key field depend on the whole key? If some field depends on part of it, there is a partial dependency 部分依赖 and the table is not in 2NF. Does every non-key field depend on the key alone? If a field depends on another non-key field, there is a transitive dependency and the table is not in 3NF. An "explain why the table is not in 3NF" answer names the dependency and the fields involved.

Worked example. A car-rental shop records each rental as RENTAL(RentalID, RentalDate, CustomerID, CustomerName, CustomerPhone, CarReg, CarModel, DailyRate, Days), where one rental can include several cars. Explain why the table is not normalised and produce a 3NF design.

Not in 1NF: the car fields CarReg, CarModel, DailyRate, Days form a repeating group — one rental has several cars. Move them to RENTAL_CAR(RentalID, CarReg, CarModel, DailyRate, Days) with the composite key (RentalID, CarReg). Not in 2NF: in RENTAL_CAR, CarModel and DailyRate depend on CarReg alone — a partial dependency. Move them to CAR(CarReg, CarModel, DailyRate), leaving RENTAL_CAR(RentalID, CarReg, Days). Not in 3NF: in RENTAL, CustomerName and CustomerPhone depend on CustomerID, a non-key field — a transitive dependency. Move them to CUSTOMER(CustomerID, CustomerName, CustomerPhone), leaving RENTAL(RentalID, RentalDate, CustomerID). The 3NF design is four tables — CUSTOMER, RENTAL, RENTAL_CAR, CAR — with CustomerID, RentalID and CarReg as foreign keys; underline every primary key.

العربية

التطبيع ينظم الجداول لـ تقليل التكرار وعدم الاتساق، وذلك بالمرور عبر الأشكال المعيارية بالترتيب.

  • الشكل المعياري الأول (1NF) — كل حقل يحمل قيمة واحدة (ذرية)، بدون مجموعات متكررة، ويحتوي على مفتاح أساسي.
  • الشكل المعياري الثاني (2NF) — في 1NF، ويعتمد كل حقل غير مفتاحي على الكامل للمفتاح الأساسي (وهذا يهم فقط المفاتيح المركبة).
  • الشكل المعياري الثالث (3NF) — في 2NF، ويعتمد كل حقل غير مفتاحي فقط على المفتاح الأساسي، وليس على حقل غير مفتاحي آخر (لا توجد اعتمادية متزامنة).

تخزن تصميم 3NF كل حقيقة مرة واحدة، مما يختفي به شذوذ الإدراج/التحديث/الحذف. المقابل هو وجود جداول أكثر وعمليات ربط أكثر. استهدف تصميم 3NF.

للحصول على تصميم 3NF: حدد الكيانيات وخصائصها؛ اختر مفتاحًا أساسيًا لكل منها؛ قم بتقسيم الحقول المتكررة/غير الذرية (1NF)؛ قم بتقسيم الحقول التي تعتمد على جزء من مفتاح مركب (2NF)؛ قم بتقسيم الحقول التي تعتمد اعتمادية متزامنة على المفتاح (3NF)؛ أضف مفاتيح أجنبية للعلاقات.

التطبيع: جدول واحد كان اسم العميل والهاتف يتكرر في كل طلب يتم تقسيمه إلى جدول منفصل للطلبات وجدول للعملاء، بحيث تُخزن كل حقيقة مرة واحدة
التطبيع يزيل التكرار عن طريق فصل البيانات المكررة في جدول خاص بها

مثال محلول. الجدول ORDER(OrderID, CustomerID, CustomerName, ProductID, Quantity) يمتلك المفتاح الأساسي المركب (OrderID, ProductID). قم بتطبيعه ليصل إلى 3NF. اختبر كل حقل غير مفتاحي ضد المفتاح. يعتمد Quantity على كلا OrderID وProductID، وهذا مقبول. لكن CustomerID يعتمد على OrderID وحدها - وهو جزء من المفتاح المركب. هذا اعتماد جزئي، لذا الجدول ليس في 2NF. قسّمه إلى ORDER_LINE(OrderID, ProductID, Quantity) وORDER(OrderID, CustomerID, CustomerName). الآن اختبر 3NF: في جدول ORDER الجديد، يعتمد CustomerName على CustomerID، وهو ليس المفتاح - اعتمادية متزامنة. قسّم مرة أخرى: ORDER(OrderID, CustomerID) وCUSTOMER(CustomerID, CustomerName). سمّ الاعتمادية التي تكسر كل شكل (الجزئي يكسر 2NF، والمتزامن يكسر 3NF)؛ أما قول "يوجد بيانات مكررة" فيصف العرض ولا يمنح أي نقاط.

الثلاثة أسئلة التي يجب طرحها على أي جدول. هل كل خلية قيمة واحدة، بدون مجموعة مكررة؟ إذا لم يكن الأمر كذلك، فهو ليس في 1NF. إذا كان المفتاح مركبًا، هل يعتمد كل حقل غير مفتاحي على المفتاح الكامل؟ إذا كان بعض الحقول يعتمد على جزء منه، فهناك اعتماد جزئي والجدول ليس في 2NF. هل يعتمد كل حقل غير مفتاحي على المفتاح وحده؟ إذا كان الحقل يعتمد على حقل غير مفتاحي آخر، فهناك اعتمادية متزامنة والجدول ليس في 3NF. إجابة "اشرح لماذا الجدول ليس في 3NF" تذكر نوع الاعتمادية والحقول المعنية.

تطبيع جدول تأجير سيارات في ثلاث خطوات: إزالة المجموعة المتكررة للسيارات من أجل 1NF، نقل تفاصيل السيارة التي تعتمد على رقم تسجيل السيارة وحدها إلى جدول سيارات من أجل 2NF، ونقل تفاصيل العميل التي تعتمد على معرف العميل إلى جدول عملاء من أجل 3NF
1NF يزيل المجموعة المتكررة، 2NF يزيل الاعتماد الجزئي، 3NF يزيل الاعتمادية المتزامنة

مثال محلول. تسجل ورشة تأجير السيارات كل عملية تأجير كـ RENTAL(RentalID, RentalDate, CustomerID, CustomerName, CustomerPhone, CarReg, CarModel, DailyRate, Days)، حيث يمكن أن تتضمن عملية التأجير عدة سيارات. اشرح لماذا الجدول غير مطبّع وأنتج تصميم 3NF.

غير في 1NF: حقول السيارات CarReg, CarModel, DailyRate, Days تشكل مجموعة متكررة — حيث يحتوي كل تأجير على سيارات متعددة. انقلها إلى RENTAL_CAR(RentalID, CarReg, CarModel, DailyRate, Days) مع المفتاح المركب (RentalID, CarReg). غير في 2NF: في RENTAL_CAR، CarModel وDailyRate تعتمد على CarReg وحدها — وهو اعتماد جزئي. انقلها إلى CAR(CarReg, CarModel, DailyRate)، واترك RENTAL_CAR(RentalID, CarReg, Days). غير في 3NF: في RENTAL، CustomerName وCustomerPhone تعتمد على CustomerID، وهو حقل غير مفتاحي — وهذا اعتماد متعدٍ. انقلها إلى CUSTOMER(CustomerID, CustomerName, CustomerPhone)، واترك RENTAL(RentalID, RentalDate, CustomerID). تصميم 3NF يتكون من أربع جداول — CUSTOMER، RENTAL، RENTAL_CAR، CAR — مع CustomerID، RentalID وCarReg كمفاتيح خارجية؛ تحط خطاً تحت كل مفتاح أساسي.

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
normalisation/ˌnɔːməlaɪˈzeɪʃn/ التطبيع
normal forms/ˈnɔːml fɔːmz/ الصيغ الطبيعية
atomic/əˈtɒmɪk/ ذرية
transitive dependency/ˈtrænsɪtɪv dɪˈpendənsi/ التبعيات الانتقالية
partial dependency/ˈpɑːʃl dɪˈpendənsi/ اعتماد جزئي
data dictionary/ˈdeɪtə ˈdɪkʃənəri/ قاموس البيانات
concurrent access/kənˈkʌrənt ˈækses/ الوصول المتزامن
transactions/trænˈsækʃnz/ العمليات
backup/ˈbækʌp/ النسخ الاحتياطي
views/vjuːz/ مشاهدات
data management/ˈdeɪtə ˈmænɪdʒmənt/ إدارة البيانات
data modelling/ˈdeɪtə ˈmɒdəlɪŋ/ نمذجة البيانات
logical schema/ˈlɒdʒɪkl ˈskiːmə/ المخطط المنطقي
data integrity/ˈdeɪtə ɪnˈteɡrɪti/ سلامة البيانات
data security/ˈdeɪtə sɪˈkjʊərɪti/ أمان البيانات
query processor/ˈkwɪərɪ ˈprəʊsesə/ معالج الاستعلامات
developer interface/dɪˈveləpə ˈɪntəfeɪs/ واجهة المطور
authentication/ɔːˌθentɪˈkeɪʃn/ المصادقة
Data Definition Language/ˈdeɪtə ˌdefɪˈnɪʃn ˈlæŋɡwɪdʒ/ لغة تعريف البيانات
Data Manipulation Language/ˈdeɪtə məˌnɪpjʊˈleɪʃn ˈlæŋɡwɪdʒ/ لغة معالجة البيانات
aggregate functions/ˈæɡrɪɡeɪt ˈfʌŋkʃnz/ الدوال المجمعة
8.2

Database Management System (DBMS) · ⁨نظام إدارة قواعد البيانات (DBMS)⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding of the features provided by a Database Management System (DBMS) that address the issues of a file based approach Including: • data management, including maintaining a data dictionary • data modelling • logical schema • data integrity • data security, including backup procedures and the use of access rights to individuals / groups of users
Show understanding of how software tools found within a DBMS are used in practice Including the use and purpose of: • developer interface • query processor
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
إظهار فهم الميزات المقدمة من قبل نظام إدارة قواعد البيانات (DBMS) والتي تعالج مشاكل النهج القائم على الملفات بما في ذلك: • إدارة البيانات، بما في ذلك الحفاظ على قاموس البيانات • تصميم البيانات • المخطط المنطقي • نزاهة البيانات • أمان البيانات، بما في ذلك إجراءات النسخ الاحتياطي واستخدام حقوق الوصول للأفراد / مجموعات المستخدمين
إظهار فهم كيفية استخدام أدوات البرمجيات الموجودة داخل DBMS عملياً بما في ذلك الاستخدام والهدف من: • واجهة المطور • معالج الاستعلامات

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

A DBMS 数据库管理系统 manages the database centrally. Features that fix the file-based limits:

  • data dictionary 数据字典 — a description of every table, field, type and key; programs query it instead of hard-coding the structure.
  • redundancy/consistency control — each fact stored once.
  • concurrent access 并发访问 control — locks and transactions let many users work at once.
  • backup 备份 and recovery; security and per-user permissions.
  • integrity rules — keys, unique and range constraints, enforced centrally.
  • transactions 事务 — a group of operations that all succeed or all fail.
  • views 视图 — virtual tables that show each user "their" slice of the data.
  • data management 数据管理 and data modelling 数据建模 — control how data is stored and define its structure as a logical schema 逻辑模式 (the logical design, independent of physical storage).
  • data integrity 数据完整性 and data security 数据安全 — enforce correctness and control access centrally.
  • a query processor 查询处理器 runs queries; a developer interface 开发者接口 gives tools and APIs for building applications.

Its tools include a data-dictionary editor, a query builder, a forms builder, a report generator, user management, and an SQL editor.

What the data dictionary holds (a "give three items" question): the names of the tables; the names of the fields in each table; each field's data type and length; the primary and foreign keys and the relationships between tables; validation rules; indexes; and who may access each table. It is metadata — data about the data — and the DBMS uses it to check every query and every change.

How the DBMS keeps the data secure (a "describe two methods" question): authentication 身份验证 — a username and password, or a biometric, before any access; access rights — each user or group is allowed to read, write or delete only certain tables or fields, often through a view; encryption of the stored data and of data sent to it, so a copied file is unreadable; backups taken regularly, so the data can be restored after loss; and a transaction log that records who changed what.

The two software tools. The developer interface is what a programmer uses to build the database and the applications on it: create tables and set keys and validation, write queries and SQL, and design forms and reports, without knowing how the data is physically stored. The query processor takes a query (SQL from a program, or a query built in the interface), checks it against the data dictionary, works out the most efficient way to run it, retrieves the data and returns the results.

Logical schema. The DBMS keeps the logical design (which tables and fields exist and how they relate) separate from the physical storage (files, indexes, disk blocks). Programs work with the logical schema, so the physical storage can be reorganised without changing a single program — this is the data independence the file-based approach lacked.

العربية

نظام إدارة قواعد البيانات (DBMS) يدير قاعدة البيانات بشكل مركزي. الميزات التي تصحح حدود الملفات التقليدية:

  • قاموس البيانات — وصف لكل جدول، وحقل، ونوع ومفتاح؛ تقوم البرامج باستعلامه بدلاً من برمجة البنية يدوياً.
  • التحكم في التكرار/الاتساق — تخزين كل حقيقة مرة واحدة فقط.
  • التحكم في الوصول المتزامن — الأقفال والعمليات تتيح لعدة مستخدمين العمل في آن واحد.
  • النسخ الاحتياطي والاستعادة؛ والأمان وصلاحيات المستخدم لكل مستخدم.
  • قواعد النزاهة — المفاتيح، والقيود الفريدة والنطاقية، يتم فرضها بشكل مركزي.
  • العمليات — مجموعة من العمليات تنجح جميعها أو تفشل جميعها.
  • العرض — جداول افتراضية تعرض لكل مستخدم "جزءته" من البيانات.
  • إدارة البيانات ونمذجة البيانات — التحكم في كيفية تخزين البيانات وتعريف بنيتها كـ مخطط منطقي (التصميم المنطقي، المستقل عن التخزين الفيزيائي).
  • نزاهة البيانات وأمان البيانات — فرض الصواب والتحكم في الوصول بشكل مركزي.
  • معالج الاستعلامات يشغل الاستعلامات؛ وواجهة المطور توفر أدوات وواجهات برمجية لإنشاء التطبيقات.

تشمل أدواته محرر قاموس البيانات، وباني الاستعلامات، وباني النماذج، ومولد التقارير، وإدارة المستخدمين، ومحرر SQL.

ما يحتويه قاموس البيانات (سؤال "اذكر ثلاث عناصر"): أسماء الجداول؛ وأسماء الحقول في كل جدول؛ ونوع وطول كل حقل؛ والمفاتيح الأساسية والخارجية والعلاقات بين الجداول؛ وقواعد التحقق؛ والفهارس؛ ومن يحق له الوصول إلى كل جدول. إنه بيانات وصفية — بيانات حول البيانات — ويستخدمها نظام إدارة قواعد البيانات للتحقق من كل استعلام وكل تغيير.

كيف يحافظ نظام إدارة قواعد البيانات على أمان البيانات (سؤال "وصف طريقتين"): المصادقة — اسم مستخدم وكلمة مرور، أو ملامح حيوية، قبل أي وصول؛ صلاحيات الوصول — يُسمح لكل مستخدم أو مجموعة بقراءة أو كتابة أو حذف جداول أو حقول معينة فقط، غالباً عبر عرض؛ تشفير البيانات المخزنة والبيانات المرس إليها، بحيث تكون ملفاً منسوخاً غير مقروء؛ النسخ الاحتياطية المأخوذة بانتظام، بحيث يمكن استعادة البيانات بعد الفقدان؛ وسجل عمليات يسجل من غيّر ماذا.

الأدوات البرمجية اثنتان. واجهة المطور هي ما يستخدمه المبرمج لبناء قاعدة البيانات والتطبيقات عليها: إنشاء الجداول وضبط المفاتيح والتحقق، وكتابة الاستعلامات وSQL، وتصميم النماذج والتقارير، دون الحاجة لمعرفة كيفية تخزين البيانات فيزيائياً. معالج الاستعلامات يستقبل استعلاماً (SQL من برنامج، أو استعلام مُنشأ في الواجهة)، ويتحقق منه مقابل قاموس البيانات، ويحدد الطريقة الأكثر كفاءة لتنفيذه، ويسترجع البيانات ويعيد النتائج.

المخطط المنطقي. يحافظ نظام إدارة قواعد البيانات على التصميم المنطقي (أي الجداول والحقول الموجودة وكيف ترتبط) منفصلاً عن التخزين الفيزيائي (الملفات، والفهارس، وكتل القرص). تعمل البرامج مع المخطط المنطقي، لذا يمكن إعادة تنظيم التخزين الفيزيائي دون تغيير أي برنامج — وهذا هو استقلال البيانات الذي افتقرت إليه طريقة الملفات التقليدية.

محرك قرص صلب بغطائه مرفوع، يُظهر الأقراص الدائرية المتراصة ذات السطح المرآتي وذراع رأس القراءة/الكتابة مستقرًا فوقها
التخزين الفيزيائي الذي يخفيه المخطط المنطقي: أقراص محرك القرص الصلب الدوارة ورأس القراءة/الكتابة
Explore · ⁨استكشف⁩

Database service lab · ⁨معمل خدمة قواعد البيانات⁩

Watch how a DBMS turns a query into safe shared data access. · ⁨شاهد كيف يحول نظام إدارة قواعد البيانات الاستعلام إلى وصول آمن ومشارك للبيانات.⁩

Explore · ⁨استكشف⁩

Database service lab · ⁨معمل خدمة قواعد البيانات⁩

Watch how a DBMS turns a query into safe shared data access. · ⁨شاهد كيف يحول نظام إدارة قواعد البيانات الاستعلام إلى وصول آمن ومشارك للبيانات.⁩

8.3

DDL and DML · ⁨DDL وDML⁩

Syllabus · ⁨المنهج⁩
English
Candidates should be able to: Notes and guidance
Show understanding that the DBMS carries out all creation/modification of the database structure using its Data Definition Language (DDL)
Show understanding that the DBMS carries out all queries and maintenance of data using its DML
Show understanding that the industry standard for both DDL and DML is Structured Query Language (SQL) Understand a given SQL statement
Understand given SQL (DDL) statements and be able to write simple SQL (DDL) statements using a sub-set of statements Create a database (CREATE DATABASE) Create a table definition (CREATE TABLE), including the creation of attributes with appropriate data types: • CHARACTER • VARCHAR(n) • BOOLEAN • INTEGER • REAL • DATE • TIME change a table definition (ALTER TABLE) add a primary key to a table (PRIMARY KEY (field)) add a foreign key to a table (FOREIGN KEY (field) REFERENCES Table (Field))
Write an SQL script to query or modify data (DML) which are stored in (at most two) database tables Queries including SELECT... FROM, WHERE, ORDER BY, GROUP BY, INNER JOIN, SUM, COUNT, AVG
Data maintenance including INSERT INTO, DELETE FROM, UPDATE
العربية
يجب أن يكون المرشحون قادرين على: ملاحظات وإرشادات
إظهار فهم أن DBMS يقوم بجميع عمليات إنشاء/تعديل هيكل قاعدة البيانات باستخدام لغة تعريف البيانات (DDL)
إظهار فهم أن DBMS يقوم بجميع استعلامات وصيانة البيانات باستخدام DML
إظهار فهم أن المعيار الصناعي لكل من DDL و DML هو لغة الاستعلام الهيكلي (SQL) فهم جملة SQL محددة
فهم جمل SQL (DDL) المحددة والقدرة على كتابة جمل SQL (DDL) بسيطة باستخدام مجموعة فرعية من الجمل إنشاء قاعدة بيانات (CREATE DATABASE) إنشاء تعريف جدول (CREATE TABLE)، بما في ذلك إنشاء سمات بأنواع بيانات مناسبة: • CHARACTER • VARCHAR(n) • BOOLEAN • INTEGER • REAL • DATE • TIME تغيير تعريف جدول (ALTER TABLE) إضافة مفتاح أساسي لجدول (PRIMARY KEY (field)) إضافة مفتاح أجنبي لجدول (FOREIGN KEY (field) REFERENCES Table (Field))
كتابة سكريبت SQL لاستعلام أو تعديل البيانات (DML) المخزنة في (أقصى حد اثنين) جداول قاعدة بيانات الاستعلامات تشمل SELECT... FROM، WHERE، ORDER BY، GROUP BY، INNER JOIN، SUM، COUNT، AVG
صيانة البيانات بما في ذلك INSERT INTO، DELETE FROM، UPDATE

Source: Cambridge International syllabus · ⁨المصدر: منهج كامبريدج الدولي⁩

English

SQL 结构化查询语言 (Structured Query Language) has two halves:

  • Data Definition Language 数据定义语言 (DDL) — creates or changes the structure (tables, keys, constraints).
  • Data Manipulation Language 数据操纵语言 (DML) — works with the data (insert, update, delete, query 查询).

DDL basics

Add a foreign key:

Modify and drop:

Common types: INTEGER, REAL, VARCHAR(n), CHAR(n) (also CHARACTER(n)), DATE, TIME, BOOLEAN, DECIMAL(p, s).

DML basics

Query with SELECT:

SELECT lists fields, FROM names the table, WHERE filters rows, ORDER BY sorts.

A join 连接 combines two tables using a foreign-key relationship:

Aggregate functions 聚合函数 (COUNT, SUM, AVG, MIN, MAX) are often used with GROUP BY:

Insert, update, delete:

Always put a WHERE clause on UPDATE and DELETE, or the change hits every row.

Tips for exam SQL

  • use the exact table and field names from the question.
  • quote strings with single quotes ('Smith'); don't quote numbers.
  • comparisons: =, <, >, <=, >=, <>.
  • LIKE 'A%' matches anything starting with A (% = any string, _ = one character); IN (1,2,3); BETWEEN 10 AND 20.
  • combine conditions with AND / OR / NOT, and end each statement with a semicolon.

The DDL pattern the exam wants. Every CREATE TABLE names each field with its type, marks the primary key, and declares each foreign key with the table it references; a composite key is declared on its own line:

Worked example. Using CUSTOMER(CustomerID, Name, Phone) and DEVICE(DeviceID, CustomerID, Type, Model), write SQL scripts to: (a) list the name and phone number of every customer who owns a device of type 'tablet', in alphabetical order of name; (b) count the devices of each type; (c) record that customer 17 now has the phone number '0771 234 5678'; (d) add a new device, ID 305, a 'laptop' of model 'X1' belonging to customer 17.

(a)

(b)

(c) UPDATE CUSTOMER SET Phone = '0771 234 5678' WHERE CustomerID = 17; (d) INSERT INTO DEVICE (DeviceID, CustomerID, Type, Model) VALUES (305, 17, 'laptop', 'X1');

Marks are given per clause — the fields, the tables, the join condition, the WHERE, the ORDER BY — so a script with one wrong clause still scores the rest. Write Table.Field whenever two tables are involved.

Worked example. Explain what this script does: SELECT T.Name, SUM(R.Cost) AS Total FROM TECHNICIAN T INNER JOIN REPAIR R ON T.TechnicianID = R.TechnicianID GROUP BY T.Name;

It outputs each technician's name with the total cost of the repairs that technician has carried out, one row per technician: the two tables are joined on TechnicianID, the rows are grouped by name, and the costs in each group are added. When asked what a script does, describe the result, not the syntax.

العربية

SQL (لغة الاستعلامات المهيكلة) تتكون من نصفين:

SQL ينقسم إلى DDL (يبني البنية) وDML (يعمل مع البيانات)
DDL يبني بنية قاعدة البيانات؛ DML يعمل مع البيانات
  • لغة تعريف البيانات (DDL) — تنشئ أو تعدل البنية (الجداول، المفاتيح، القيود).
  • لغة معالجة البيانات (DML) — تعمل مع البيانات (الإدراج، التحديث، الحذف، الاستعلام).

أساسيات DDL

CREATE TABLE CUSTOMER (
  CustomerID INTEGER PRIMARY KEY,
  Name VARCHAR(50) NOT NULL,
  Phone VARCHAR(20)
);

إضافة مفتاح خارجي:

CREATE TABLE ORDER (
  OrderID INTEGER PRIMARY KEY,
  CustomerID INTEGER,
  OrderDate DATE,
  FOREIGN KEY (CustomerID) REFERENCES CUSTOMER(CustomerID)
);

تعديل وحذف:

ALTER TABLE CUSTOMER ADD Email VARCHAR(100);
DROP TABLE CUSTOMER;

الأنواع الشائعة: INTEGER، REAL، VARCHAR(n)، CHAR(n) (أيضاً CHARACTER(n))، DATE، TIME، BOOLEAN، DECIMAL(p, s).

أساسيات DML

استعلام باستخدام SELECT:

استعلام SELECT يعيد فقط الصفوف التي تطابق شرطه
استعلام SELECT يعيد فقط الصفوف التي تطابق شرطه
SELECT Name, Phone
FROM CUSTOMER
WHERE City = 'London'
ORDER BY Name ASC;

SELECT يسرد الحقول، FROM يحدد اسم الجدول، WHERE يرشح الصفوف، ORDER BY يرتب.

الـ join يدمج جدولين باستخدام علاقة المفتاح الخارجي:

SELECT C.Name, O.OrderDate
FROM CUSTOMER C INNER JOIN ORDER O
  ON C.CustomerID = O.CustomerID
WHERE O.OrderDate >= '2024-01-01';
استعلام SQL مُعلّق سطرًا بسطر: SELECT يحدد الحقول وعمود COUNT، FROM يحدد الجدول الأول مع اختصار، INNER JOIN ON يربط الجدول الثاني عبر المفتاح الخارجي، WHERE يحفظ الصفوف المطابقة، GROUP BY يجعل صفًا واحدًا لكل عميل، ORDER BY يرتب النتيجة
أجزاء الاستعلام، بالترتيب الذي يجب كتابته به

الدوال المجمعة (COUNT، SUM، AVG، MIN، MAX) تُستخدم غالبًا مع GROUP BY:

SELECT CustomerID, COUNT(*) AS NumOrders
FROM ORDER
GROUP BY CustomerID;

إدراج، تحديث، حذف:

INSERT INTO CUSTOMER (CustomerID, Name, Phone)
VALUES (101, 'Ada Lovelace', '020-1234-5678');

UPDATE CUSTOMER SET Phone = '020-9999-0000' WHERE CustomerID = 101;

DELETE FROM CUSTOMER WHERE CustomerID = 101;

ضع دائمًا جملة WHERE على UPDATE وDELETE، وإلا سيصل التغيير إلى كل صف.

نصائح لـ SQL في الامتحان

  • استخدم أسماء الجداول والحقول الدقيقة من السؤال.
  • ضع النصوص بين علامات اقتباس مفردة ('Smith')؛ ولا تضع أرقامًا بين علامات اقتباس.
  • المقارنات: =، <، >، <=، >=، <>.
  • LIKE 'A%' يطابق أي شيء يبدأ بـ A (% = أي سلسلة نصية، _ = حرف واحد)؛ IN (1,2,3)؛ BETWEEN 10 AND 20.
  • اجمع الشروط باستخدام AND / OR / NOT، وأنهِ كل statement بنقطة فاصلة.

نموذج DDL المطلوب في الامتحان. يُسمي كل CREATE TABLE حقلاً مع نوعه، ويحدد المفتاح الأساسي، ويعلن كل مفتاح أجنبي مع الجدول الذي يشير إليه؛ والمفتاح المركب يُعلَن على سطر مستقل:

CREATE TABLE RENTAL_CAR (
  RentalID INTEGER,
  CarReg VARCHAR(8),
  Days INTEGER,
  PRIMARY KEY (RentalID, CarReg),
  FOREIGN KEY (RentalID) REFERENCES RENTAL(RentalID),
  FOREIGN KEY (CarReg) REFERENCES CAR(CarReg)
);

مثال محلول. باستخدام CUSTOMER(CustomerID, Name, Phone) وDEVICE(DeviceID, CustomerID, Type, Model)، اكتب scripts SQL لـ: (أ) عرض اسم ورقم هاتف كل عميل يمتلك جهازًا من نوع 'tablet'، مرتبًا أبجديًا حسب الاسم؛ (ب) عدّ الأجهزة لكل نوع؛ (ج) تسجيل أن العميل رقم 17 أصبح له رقم الهاتف '0771 234 5678'؛ (د) إضافة جهاز جديد، المعرّف 305، وهو 'laptop' من الطراز 'X1' تابع للعميل 17.

(a)

SELECT CUSTOMER.Name, CUSTOMER.Phone
FROM CUSTOMER INNER JOIN DEVICE
  ON CUSTOMER.CustomerID = DEVICE.CustomerID
WHERE DEVICE.Type = 'tablet'
ORDER BY CUSTOMER.Name ASC;

(b)

SELECT Type, COUNT(DeviceID) AS NumberOfDevices
FROM DEVICE
GROUP BY Type;

(c) UPDATE CUSTOMER SET Phone = '0771 234 5678' WHERE CustomerID = 17; (d) INSERT INTO DEVICE (DeviceID, CustomerID, Type, Model) VALUES (305, 17, 'laptop', 'X1');

تُمنح الدرجات لكل clause — الحقول، الجداول، شرط الربط، WHERE، ORDER BY — لذا فإن script يحتوي على خطأ واحد في clause واحدة لا يزال يحصل على درجات باقي الأقسام. اكتب Table.Field كلما كانت هناك جدولين مشاركين.

مثال محلول. اشرح ما يفعله هذا script: SELECT T.Name, SUM(R.Cost) AS Total FROM TECHNICIAN T INNER JOIN REPAIR R ON T.TechnicianID = R.TechnicianID GROUP BY T.Name;

يُخرج اسم كل فني مع إجمالي تكلفة الإصلاحات التي أجراها، صف واحد لكل فني: تم ربط الجدولين عبر TechnicianID، وتجميع الصفوف حسب الاسم، وجمع التكاليف داخل كل مجموعة. عند السؤال عن وظيفة script، صف النتيجة وليس الصيغة.

Explore · ⁨استكشف⁩

Stitch two tables with INNER JOIN · ⁨ربط جدولين باستخدام INNER JOIN⁩

A join matches rows where the foreign key equals the primary key — here Orders.CustomerID = Customer.CustomerID — and combines each matching pair into one wider row. · ⁨ي matcher الربط الصفوف حيث يساوي المفتاح الأجنبي المفتاح الأساسي — هنا Orders.CustomerID = Customer.CustomerID — ويجمع كل زوج مطابق في صف واحد أعرض.⁩

Explore · ⁨استكشف⁩

SELECT … WHERE

Step through a query: WHERE keeps the rows that match, then SELECT picks the columns you asked for. · ⁨مرر عبر استعلام: يحفظ WHERE الصفوف المطابقة، ثم يختار SELECT الأعمدة التي طلبتها.⁩

Vocabulary · ⁨مفردات⁩ Train · ⁨تدريب⁩
English العربية
flat files/flæt faɪlz/ ملفات مسطحة
data redundancy/ˈdeɪtə rɪˈdʌndənsi/ تكرار البيانات
data inconsistency/ˈdeɪtə ˌɪnkənˈsɪstənsi/ عدم اتساق البيانات
field/fiːld/ حقل
integrity/ɪnˈteɡrɪti/ الموثوقية
relational database/rɪˈleɪʃənl ˈdeɪtəbeɪs/ قاعدة بيانات علائقية
query/ˈkwɪərɪ/ استعلام
primary key/ˈpraɪməri kiː/ المفتاح الأساسي
foreign key/ˈfɒrən kiː/ المفتاح الأجنبي
composite key/ˈkɒmpəzɪt kiː/ المفتاح المركب
candidate key/ˈkændɪdeɪt kiː/ المفتاح المرشح
secondary key/ˈsekəndəri kiː/ المفتاح الثانوي
indexing/ˈɪndeksɪŋ/ الفهرسة
join/dʒɔɪn/ join (لا تترجم، استخدم term)
referential integrity/ˌrefəˈrenʃl ɪnˈteɡrɪti/ سلامة المرجعية
entity-relationship diagram/ˈentɪti rɪˈleɪʃənʃɪp ˈdaɪəɡræm/ مخطط الكائنات والعلاقات
Watch lesson · ⁨شاهد الدرس⁩
8.3

Definitions the examiner accepts · ⁨التعريفات التي يقبلها المصحح⁩

English

A definition question is marked against fixed wording. Learn these exactly, and give one answer only.

Term Definition
entity something about which data is stored — a person, object or event — which becomes a table in a relational database
attribute one item of data about an entity (a column of the table)
tuple one row of a table: one instance of the entity
primary key an attribute, or combination of attributes, that uniquely identifies each record in a table
foreign key an attribute in one table whose value matches a primary key in another table, used to link the two
candidate key any attribute (or combination) that could be chosen as the primary key
secondary key a non-primary attribute that is indexed so the table can be searched or sorted on it quickly
composite key a primary key made of two or more attributes together
referential integrity every foreign-key value must match an existing primary-key value in the table it refers to
first normal form a table in which every attribute is atomic, there are no repeating groups, and there is a primary key
second normal form in 1NF, and every non-key attribute depends on the whole of the primary key (no partial dependency)
third normal form in 2NF, and no non-key attribute depends on another non-key attribute (no transitive dependency)
data dictionary the metadata a DBMS keeps about the structure of the database: tables, fields, types, keys, relationships, validation
DDL / DML the language used to define or change the structure of a database / the language used to query and maintain the data in it
العربية

تُصنّف أسئلة التعريف بناءً على صياغة ثابتة. احفظ هذه التعريفات بدقة، وقدم إجابة واحدة فقط.

مصطلح تعريف
كيان شيء تُخزن حوله البيانات — شخص أو جسم أو حدث — والذي يتحول إلى جدول في قاعدة بيانات علائقية
صفة عنصر بيانات واحد عن كيان (عمود في الجدول)
شريط صف واحد من الجدول: حالة واحدة للكيان
مفتاح أساسي صفة أو مجموعة صفات تميز كل سجل في الجدول بشكل فريد
مفتاح أجنبي صفة في جدول واحد تكون قيمته مطابقة لمفتاح أساسي في جدول آخر، تُستخدم لربط الجدولين
مفتاح مرشح أي صفة (أو مجموعة) يمكن اختيارها كمفتاح أساسي
مفتاح ثانوي صفة غير أساسية يتم فهرستها بحيث يمكن البحث في الجدول أو ترتيبه بسرعة بناءً عليها
مفتاح مركب مفتاح أساسي يتكون من صفتين أو أكثر معًا
سلامة المرجع يجب أن تطابق قيمة كل مفتاح أجنبي قيمة مفتاح أساسي موجودة في الجدول الذي تشير إليه
الشكل الطبيعي الأول جدول تكون فيه كل صفة ذرية، ولا توجد مجموعات متكررة، ويوجد مفتاح أساسي
الشكل الطبيعي الثاني في 1NF، وتعتمد كل صفة غير مفتاحية على المفتاح الأساسي بأكمله (لا يوجد اعتماد جزئي)
الشكل الطبيعي الثالث في 2NF، ولا تعتمد أي صفة غير مفتاحية على صفة غير مفتاحية أخرى (لا يوجد اعتماد متسلسل)
قاموس البيانات البيانات الوصفية التي يحفظها DBMS حول هيكل قاعدة البيانات: الجداول، الحقول، الأنواع، المفاتيح، العلاقات، التحقق
DDL / DML اللغة المستخدمة لتعريف أو تغيير هيكل قاعدة البيانات / اللغة المستخدمة لاستعلام وصيانة البيانات فيها
8.3

Exam tips · ⁨نصائح للامتحان⁩

English
  • Define the terms exactly: entity, attribute, primary key, foreign key, and the relationship types (1:1, 1:many, many:many).
  • Give a reason at each normal form: 1NF (no repeating groups), 2NF (no partial dependency), 3NF (no non-key dependency) — and name the fields involved.
  • Explain what a DBMS provides (data independence, security, integrity, concurrent access, a data dictionary, a developer interface, a query processor).
  • Distinguish DDL (define the structure) from DML (query and change the data), and write SQL clause by clause: SELECT, FROM, INNER JOIN … ON, WHERE, GROUP BY, ORDER BY.
  • To draw an E-R diagram from tables, find each foreign key first: every foreign key is one one-to-many relationship, with the "many" at the table that holds it.

Common mistakes

  • Drawing a many-to-many relationship directly. It must be split into two one-to-many relationships through a link table holding both foreign keys.
  • Explaining "not in 3NF" by "the data is repeated". Name the dependency (partial or transitive) and the fields involved.
  • Double quotes round strings in SQL, or quotes round numbers. Strings take 'single quotes'; numbers take none.
  • Leaving out the ON condition after INNER JOIN. Without it the two tables are not linked.
  • Putting an ordinary field next to COUNT or SUM in a SELECT without a GROUP BY.
  • UPDATE or DELETE without a WHERE. It changes or removes every row in the table.
العربية
  • عرّف المصطلحات بدقة: الكيان، الصفة، المفتاح الأساسي، المفتاح الأجنبي، وأنواع العلاقة (1:1، 1:كثير، كثير:كثير).
  • قدم سببًا عند كل شكل طبيعي: 1NF (عدم وجود مجموعات متكررة)، 2NF (عدم وجود اعتماد جزئي)، 3NF (عدم وجود اعتماد غير مفتاحي) — وسمِّ الحقول المعنية.
  • اشرح ما يوفره DBMS (استقلالية البيانات، الأمان، السلامة، الوصول المتزامن، قاموس البيانات، واجهة المطور، معالج الاستعلام).
  • اميز بين DDL (تعريف البنية) و DML (الاستعلام عن البيانات وتغييرها)، واكتب جملة SQL بنقطة بنقطة: SELECT، FROM، INNER JOIN … ON، WHERE، GROUP BY، ORDER BY.
  • لرسم مخطط E-R من الجداول، ابحث أولاً عن كل مفتاح أجنبي: كل مفتاح أجنبي يمثل علاقة واحد-إلى-كثير، حيث يكون "الكثير" في الجدول الذي يحتويه.

أخطاء شائعة

  • رسم علاقة كثير-إلى-كثير مباشرة. يجب تقسيمها إلى علاقتين واحد-إلى-كثير عبر جدول رابط يحمل كلا المفتاحين الأجانب.
  • شرح "غير في 3NF" بـ "تكرار البيانات". سمِّ الاعتماد (الجزئي أو المتسلسل) والحقول المعنية.
  • علامات التنصيص تحيط بالنصوص في SQL، أو تحيط بالأرقام. تأخذ النصوص 'single quotes'؛ والأرقام لا تأخذ شيئاً.
  • نسيان شرط ON بعد INNER JOIN. بدونه لن يتم ربط الجدولين.
  • وضع حقل عادي بجانب COUNT أو SUM في SELECT بدون GROUP BY.
  • UPDATE أو DELETE بدون WHERE.它会更改或删除表中的每一行。

Interactive lessons on this topic · ⁨دروس تفاعلية حول هذا الموضوع⁩

Work through it step by step, with instant-check exercises. · ⁨ا-working عليه خطوة بخطوة، مع تمارين تحقق فوري.⁩

Past Papers · ⁨أوراق الامتحانات السابقة⁩

More topics in A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩ · ⁨المزيد من المواضيع في A-Level Computer Science · ⁨A-Level علوم الحاسوب⁩⁩

Log in or create account · ⁨تسجيل الدخول أو إنشاء حساب⁩

IGCSE, A-Level & AP