You are on page 1of 11

5 ‫قواعد البيانات محاضرة‬

By: The_ lack_©️at


____________________________________________________
Relational Model [1] Chapter 3
Relational Model.
The relational model uses a collection of tables to represent
both data and the relationships among those data. Each table
has multiple columns, and each column has a unique name.
.‫نموذج العالئقية‬
‫يستخدم النموذج العالئقي مجموعة من الجداول لتمثيل كل من البيانات والعالقات‬
.‫ ولكل عمود اسم فريد‬، ‫ يحتوي كل جدول على أعمدة متعددة‬.‫بين تلك البيانات‬

NOTE: ‫الجداول والمخططات في الملزمة‬

The Branch table of Figure 5.1 stores information about


branches, consisting of brachNo, street, city, and pstcode, for
each branch. Note that each branch is identified by the value of
the column branch No. In general, a row in a table represents a
relationship among a set of values.
In mathematical terminology, a tuple is simply a sequence (or
list) of values. A relationship between n values is represented
mathematically by an n-tuple of values.
‫جدول الفرع من الشكل ‪ 5.1‬مخازن معلومات عن الفروع‪ ،‬وتتألف من رقم الفرع‪،‬‬
‫والشارع‪ ،‬والمدينة‪ ،‬والبسكود‪ ،‬لكل فرع‪ .‬الحظ أن كل فرع يتم تحديده من قبل قيمة‬
‫فرع العمود رقم عام بشكل عام‪ ،‬وهو صف في جدول يمثل عالقة بين مجموعة من‬
‫القيم‪.‬‬
‫في المصطلحات الرياضية ‪ ،‬تمثل المجموعة ببساطة تسلسل (أو قائمة) من القيم‪.‬‬
‫من القيم‪n-tuple .‬حسابيًا بواسطة ‪n‬يتم تمثيل العالقة بين القيم‬

‫‪Table 5.1: Alternative terminology for relational model terms.‬‬


‫‪Formal terms‬‬ ‫‪Alternative 1.‬‬ ‫‪Alternative 2‬‬
‫‪Relation.‬‬ ‫‪Table.‬‬ ‫‪File‬‬
‫‪Tuple.‬‬ ‫‪Row.‬‬ ‫‪Record‬‬
‫‪Attribute‬‬ ‫‪Column.‬‬ ‫‪Field‬‬

‫تعريفات ‪Definitions:‬‬
‫‪Relation: A relation is a table with columns and rows.‬‬
‫العالقة‪ :‬عالقة هي جدول مع األعمدة والصفوف‪.‬‬
‫‪Attribute: An attribute is a named column of a relation.‬‬
‫السمة‪ :‬سمة هو عمود مسماة لعالقة‪.‬‬
‫‪Tuple: A tuple is a row of a relation.‬‬
‫الصفوف‪:‬هو صف من العالقة‪.‬‬
Degree: The degree of a relation is the number of attributes it
contains. The degree of a relation is a property of the intension
of the relation.
‫ درجة العالقة هي‬.‫ درجة العالقة هو عدد السمات التي يحتوي عليها‬:‫درجة‬
.‫ممتلكات لتكؤال العالقة‬

Relation instance: It refers to a specific instance of a relation,


i.e., containing a specific set of rows.
‫ التي تحتوي على مجموعة‬،‫ أي‬،‫ يشير إلى مثيل معين من عالقة‬:‫مثال العالقات‬
.‫محددة من الصفوف‬
Cardinality: The cardinality of a relation is the number of tuples
it contains. The cardinality is a property of the extension of the
relation and is determined from the Particular instance of the
relation at any given moment
‫ العالقة‬.‫ أصل العالقة هو عدد المجموعات التي يحتوي عليها‬:‫العالقة األساسية‬
‫األساسية هي خاصية لتمديد العالقة ويتم تحديدها من خالل مثيل خاص للعالقة في‬
‫أي لحظة معينة‬
Relational database: a collection of normalized relations with
distinct relation names.
.‫ مجموعة من العالقات الطبيعية مع أسماء عالقات مميزة‬:‫قاعدة البيانات العالئقية‬
Domain of Attributes: It is the set of permitted values for each
attribute of a relation
‫ هو مجموعة القيم المسموح بها لكل سمة من سمات العالقة‬:‫مجال السمات‬
The null value: It is a special value that signifies that the value is
unknown or does not exist.
.‫ هي قيمة خاصة تدل على أن القيمة غير معروفة أو غير موجودة‬:‫القيمة الخالية‬

NOTE: ‫الجداول والمخططات في الملزمة‬


By: The_🅱️lack_©️at 🐾

Properties of Relations ‫خصائص العالقات‬


A relation has the following properties:
:‫العالقة لديها الخصائص التالية‬
. the relation has a name that is distinct from all other relation
names in the relational schema;
‫ العالقة لديها اسم يتميز عن جميع أسماء العالقات األخرى في المخطط العالئقي؛‬.
. each cell of the relation contains exactly one atomic (single)
value;
‫ كل خلية من العالقة يحتوي على الذاكرة الذرية (واحدة) ذاتية؛‬.
. each attribute has a distinct name;
‫ كل سمة لديها اسم متميز؛‬.
. the values of an attribute are all from the same domain;
‫ قيم السمة كلها من نفس المجال؛‬.
• each tuple is distinct; there are no duplicate tuples;
‫• كل صف متميز؛ ال توجد صف مكررة؛‬
. the order of attributes has no significance;
‫ال يطلب ترتيب السمات أهمية؛‬
. the order of tuples has no significance, theoretically.
(However, in practice, the order may affect the efficiency of
accessing tuples).
‫ قد يؤثر‬،‫ في الممارسة العملية‬،‫ ومع ذلك‬،‫ترتيب الصفوف ال تطلب اهمية نظريا‬
.)‫النظام على كفاءة الوصول إلى الصفوف‬

Relational Keys:
Relational keys are one or more attributes that uniquely
identifies each tuple in a relation.
‫ مفاتيح العالقات العالئقية هي أو واحد أو سمات التي تحدد‬:‫مفاتيح العالمات العلمية‬
.‫فريد كل ما تواجه كل شيء‬

1. Superkey
An attribute, or set of attributes, that uniquely identifies a tuple
within a relation. A superkey may contain extraneous
attributes. For example, the combination of branchNO and
street is a superkey for the relation branch. If K is a superkey,
then so is any superset of K.
1-superkey
‫ قد‬.‫ تحدد بشكل فريد الصفوف ضمن العالقة‬، ‫ أو مجموعة من السمات‬، ‫سمة‬
‫ يعتبر الجمع بين‬، ‫ على سبيل المثال‬.‫يحتوي المفتاح الفائق على سمات غريبة‬
branchNO ‫و‬street .‫مفتا ًحا رئيسيًا لفرع العالقة‬
‫إذا كان‬
‫ فذلك يعني وجود أي مجموعة فرعية من‬، ‫مفتا ًحا فائقًا‬K.

Formally, let R denote the set of attributes in the schema of


relation r. If we say that a subset K of R is a superkey for r , we
are restricting consideration to instances of relations r in
which no two distinct tuples have the same values on all
attributes in K. That is, if t1 and t2 are in r and t1 12, then t1.K
#12.K.
‫ إذا قلنا أن‬.‫ دع ار يدل على مجموعة السمات في مخطط العالقة ار‬، ‫بشكل رسمي‬
‫ فنحن نحصر النظر في مثيالت‬، ‫مجموعة فرعية كي من ار هي مفتاح رئيسي الر‬
‫العالقات التي ال يوجد فيها اثنين من التالميذ المتميزين لديهم نفس القيم على جميع‬
.‫و السمات في كي‬

2. Candidate key
A superkey such that no proper subset is a superkey within the
key relation.
A candidate key, K, for a relation R has two properties:
• uniqueness – in each tuple of R, the values of K uniquely
identify that tuple;
‫‪• irreducibility – no proper subset of K has the uniqueness‬‬
‫‪property.‬‬
‫‪ .2‬مفتاح المرشح‬
‫المفتاح الفائق بحيث ال يوجد مجموعة فرعية مناسبة هو المفتاح الفائق داخل العالقة‬
‫الرئيسية‪.‬‬
‫مفتاح الترشيح ‪( )،‬كي ‪ )،‬لعالقة (ار) له خاصتان‪:‬‬
‫• التفرد – في كل مجموعة من (ار) ‪( ،‬قيم) (كي) تحدد بشكل فريد تلك المجموعة ؛‬
‫• عدم قابلية االختزال – ال توجد مجموعة فرعية مناسبة من (كي) تحتوي على‬
‫خاصية فريدة‪.‬‬

‫‪There may be several candidate keys for a relation. Consider‬‬


‫‪the Branch relation shown in Figure 5.1. Given a value of city,‬‬
‫‪we can determine several branch offices (for example, London‬‬
‫‪has two branch offices). This attribute cannot Be a candidate‬‬
‫‪key. On the other hand, by branch Number, we can determine‬‬
‫‪at most one tuple, so that branch number is a candidate key.‬‬
‫‪Similarly, postcode is also a candidate key for this relation.‬‬
‫قد يكون هناك عدة مفاتيح مرشح لعالقة‪ .‬النظر في العالقة فرع هو مبين في الشكل‬
‫نظرا لقيمة المدينة ‪ ،‬يمكننا تحديد عدة مكاتب فرعية (على سبيل المثال ‪ ،‬يوجد‬
‫ً‬ ‫‪.5.1‬‬
‫في لندن مكتبان فرعيان)‪ .‬ال يمكن أن تكون هذه السمة مفتا ًحا للترشيح‪ .‬من ناحية‬
‫أخرى ‪ ،‬حسب رقم الفرع ‪ ،‬يمكننا تحديد عدد واحد على األكثر ‪ ،‬بحيث يكون رقم‬
‫الفرع مفتا ًحا مرش ًحا‪ .‬وبالمثل ‪ ،‬الرمز البريدي هو أيضا مفتاح مرشح لهذه العالقة‪.‬‬
Note that an instance of a relation cannot be used to prove
that an attribute or combination of attributes is a candidate
key.
‫الحظ أنه ال يمكن استخدام مثيل لعالقة لثبات أن سمة أو مجموعة من السمات هي‬
.‫مفتاح الترشيح‬
The fact that there are no duplicates for the values that appear
at a particular moment in time does not guarantee that
duplicates are not possible. However, the Presence of
duplicates in an instance can be used to show that some
attribute combination is not a candidate key. Identifying a
candidate key requires that we know the “real world’ meaning
of the attribute(s) involved so that we can decide whether
duplicates are possible.
‫حقيقة عدم وجود تكرارات للقيم التي تظهر في لحظة معينة من الزمن ال تضمن أن‬
‫ يمكن استخدام التكرارات في مثيل إلظهار أن‬، ‫ ومع ذلك‬.‫التكرارات غير ممكنة‬
‫ يتطلب تحديد مفتاح المرشح أن نعرف‬.‫بعض تركيبة السمات ليست مفتاح ترشيح‬
‫معنى "العالم الحقيقي" للسمة (السمات) المعنية حتى نتمكن من تقرير ما إذا كانت‬
.‫التكرارات ممكنة‬

3. Composite key
A key that consists of more than one attribute. The two
attributes (client number, property number) constitute a
candidate key (composite) for the viewing relation shown

‫مفتاح مركب‬
)‫ رقم العقار‬، ‫ تشكل السمتان (رقم العميل‬.‫مفتاح يتكون من أكثر من سمة واحدة‬
‫مفتاح مرشح (مركب) لعالقة المشاهدة الموضحة‬

Given a client number, , there may be several corresponding


viewings for different properties. Similarly, given a property
number, property number, there may be several clients who
viewed this property. Therefore, client number by itself or
property number by itself cannot be selected as a candidate
key. However, the combination of client number and property
number identifies at most one tuple, so, for the
Viewing relation, client number and property number together
form the composite) candidate key. If we need to consider the
possibility that a client may view a property more than once,
then we could add viewDate to the composite key. However,
we assume that
This is not necessary.
‫ قد يكون هناك عدة مرات مشاهدة مناسبة لخصائص‬، ‫عند إعطاء رقم للعميل‬
‫ قد يكون هناك العديد من‬، ‫ في ضوء رقم العقار ورقم العقار‬، ‫ وبالمثل‬.‫مختلفة‬
‫ ال يمكن تحديد رقم العميل بمفرده أو رقم‬، ‫ لذلك‬.‫العمالء الذين شاهدوا هذه الخاصية‬
‫ فإن الجمع بين رقم العميل ورقم الخاصية‬، ‫ ومع ذلك‬.‫العقار بمفرده كمفتاح مرشح‬
‫ بالنسبة لـ‬، ‫ لذلك‬، ‫يحدد على األكثر عدد واحد‬
‫ إذا‬.‫ ورقم العميل ورقم العقار م ًعا تشكل مفتاح الترشيح المركب‬، ‫عرض العالقة‬
‫ فيمكننا‬، ‫كنا بحاجة إلى النظر في إمكانية قيام العميل بعرض خاصية أكثر من مرة‬
‫ فإننا نفترض أن هذا ليس‬، ‫ ومع ذلك‬.‫إضافة تاريخ العرض إلى المفتاح المركب‬
.‫ضروريا‬

NOTE: ‫الجداول والمخططات في الملزمة‬


By: The_🅱️lack_©️at 🐾
___________________________________________________-
4. Primary key
The candidate key that is selected to identify tuples uniquely
within the key relation.
The primary key should be chosen such that its attribute values
are never, or very rarely, changed.
‫ المفتاح األساسي‬.4
.‫مفتاح المرشح المحدد لتحديد الصفوف بشكل فريد ضمن عالقة المفتاح‬
‫نادرا‬
ً ‫يجب اختيار المفتاح األساسي بحيث ال يتم تغيير قيم السمات الخاصة به أبدًا أو‬
.‫ما تتغير‬
5. Foreign key
An attribute, or set of attributes, within one relation ri that
matches the candidate key (or primary key) of another relation
r2. The relation r1 is also called the referencing relation of the
foreign key dependency, and r2 is called the referenced relation
of the foreign key.
‫‪For example, in Figure 5.1, in the Branch relation, branch‬‬
‫‪number is the primary key. However, in the Staff relation, the‬‬
‫‪branch number is a foreign key.‬‬
‫‪ .5‬المفتاح الخارجي‬
‫سمة ‪ ،‬أو مجموعة من السمات ‪ ،‬ضمن عالقة واحدة (ار ‪ )1‬تطابق مفتاح المرشح‬
‫ضا العالقة‬
‫(أو المفتاح األساسي) لعالقة أخرى (ار ‪ .)2‬تسمى العالقة (ار ‪ )1‬أي ً‬
‫المرجعية إلعتماد المفتاح الخارجي ‪ ،‬و (ار ‪ )2‬تسمى العالقة المرجعية للمفتاح‬
‫الخارجي‪.‬‬
‫على سبيل المثال ‪ ،‬في الشكل ‪ ، 5.1‬في عالقة الفرع ‪ ،‬رقم الفرع هو المفتاح‬
‫األساسي‪ .‬ومع ذلك ‪ ،‬في عالقة الموظفين ‪ ،‬رقم الفرع هو مفتاح خارجي‬

‫‪The end -_-‬‬


‫🐾 ‪By: The_🅱️lack_©️ at‬‬

You might also like