درجة نوع العلاقة Degree) (Relationship type

‫بسم هللا الرحمن الرحيم‬
Lecture( 6)
Data Modeling Using the
Entity-Relationship (ER)
Model
1
(Relationship type Degree)
‫درجة نوع العالقة‬
.‫ المشاركة في نوع العالقة‬Entity types‫هي عدد الـ‬
(Number of participant Entity type into relationship type)
2 = works – for ‫ درجة نوع العالقة‬: ‫مثال‬
2
‫نوع العالقة من الدرجة االولي ‪:‬‬
‫(تسمي بـ‬
‫(‪ )Recursive relationship type‬والعالقة في هذا‬
‫النوع تكون بين كائنات نفس الـ ‪ Entity type‬المشارك في‬
‫نوع العالقة‪.‬‬
‫مثال لعالقة من الدرجة االولي‪-:‬‬
‫‪R .T: Supervision‬‬
‫كل موظف له موظف آخر يشرف علية او (يرأسه) ولذا نجد‬
‫أن ال ‪ Employee E.T‬هي ال ‪ E .T‬الوحيدة المشاركة‬
‫في العالقة ‪Supper vision‬‬
‫‪3‬‬
e1 supervisor of e2
e2 supervised by e1
(all participating entity In R.T belong to only one E.T)
e1
r1
r2
e2
e3
4
(Ternary (-: ‫نوع العالقة من الدرجةالثالثة‬
Number of participate Entity – types In to
R.T = 3
5
‫مثال‬
father
parent
f1
r1
child
c1
mother
m1
6
‫انواع العالقات من الدرجة الثانية( ‪:(Binary Relationship types‬‬
‫من اشهر انوع العالقات (لذا تطبيق معظم قيود العالقات يتم في العالقات الثنائية)‬
‫‪7‬‬
‫قيود انواع العالقات ( ‪( Relationship types Constraints‬‬
‫من العالم الحقيقي نجد ان معظم انواع العالقات لها بعض القيود او الشروط ‪.‬‬
‫فمثال نجد في المثال (‪ )company‬ان كل موظف يجب ان يعمل في قسم واحد‬
‫فقط وهذا يعتبر شرط في نوع العالقة بين الموظف والقسم ‪.‬‬
‫وهنالك نوعين من القيود يمكن تطبيقها علي ال ‪-: R.Ts‬‬
‫‪1- Cardinality Ratio Constraints.‬‬
‫‪2- Participation Constraints‬‬
‫وهذان القيدان يعرفان ب‬
‫‪structural constraints of relationship types‬‬
‫‪8‬‬
Cont.
1-cardinality ratio constraints:‫ للعالقة الثنائية‬Cardinality ratio ‫ويتم تحديد ال‬
‫) والتي‬relationship Instances( ‫بتحديد عدد ال‬
.)participant entity ( ‫يشارك فيها‬
(Specifies the relationship type instances that
an entity can participate in)
9
Department : Employee ‫ بين‬works – for ‫ العالقة‬:‫مثال‬
Cardinality ratio = 1: N
(N zero or more)
One: Many
: ‫ كاالتي‬E .R diagram ‫ويوضح ذلك في‬
Department
1
Works-for
N
Employee
10
Cont.
Possible cardinality ratios for binary R.T s:
1: N, N: 1, 1: 1, M: N
One :Many , Many : One , One :One, Many : Many
: N:1 ‫مثال ل‬
Student
N
Teach-on
1
University
11
Cont.
one : one ‫ نوع العالقة‬: ‫مثال‬
Employee
1
Manages
1
Department
12
Cont.
Many : Many ‫ لنوع عالقة‬:‫مثال‬
Employee
M
Works-for
N
Project
13
2. Participation Constraints: (Existence Dependencies):
‫ يعتمد علي‬entity ‫وهي لتحديد ما اذا كان وجود الكائن‬
)R.T( ‫عالقة تربطه بكائن اخر عبر نوع العالقة‬
)Participation Constraints( ‫هنالك نوعين ل‬
1. Total Participation.
2. partial Participation.
14
‫ اذا افترضنا ان قانون الشركة ينص علي ان أي‬:Total Participation ‫مثال ل‬
‫ ال يمكن ان يكون موجود اال اذا‬Employee ‫موظف يجب ان يعمل في قسم معين إذا ً ال‬
)works-for instances(‫كان مشارك في ال‬
(the participation of employee in works-for R.T is total
participation) .
15
works – for instances ‫ مشاركة في ال‬Employee ‫كل الكائنات في‬
:‫ (بخطين) كاآلتي‬E.R diagram ‫يوضح ذلك في ال‬,
Employee
N
Works-for
1
Department
16
-: partial participate ‫ ل‬: ‫مثال‬
‫) ولكن‬manager( ‫نجد ان كل قسم في الشركة له رئيس‬
ً ‫ليس لكل الموظفين رؤساء اقسام (جزء من الموظفين) فاذا‬
( the participation of employee entity type n manages R.T is partial
participation)
employee
e
1
Manages
r1
r2
e
2
e
3
r3
.
.
Department
d1
d2
d3
.
.
e
4
17
‫صفات انواع العالقات‬
‫)‪)attributes for relationship types‬‬
‫يمكن ان يكون إلنواع العالقات صفات مثل ال (‪)Entity types‬‬
‫امثلة ‪ -:‬الصفه (‪ )no of hours‬عدد الساعات االسبوعية للموظف فى‬
‫المشروع (‪ )project‬يمكن ان تكون صفة لنوع العالقة (‪ ) works- on‬بين‬
‫(‪ -: )employee and project‬وتوضح فى ‪ E_R diagram‬كاآلتى‪:‬‬
‫‪No of hours‬‬
‫‪Project‬‬
‫‪18‬‬
‫‪N‬‬
‫‪Works-on‬‬
‫‪M‬‬
‫‪Employee‬‬
‫‪Cont.‬‬
‫الصفة تاريخ تعيين المدير للقسم) ‪ (start date‬يمكن ان يكون صفة للعالقة‬
‫(‪ )manages‬بين (‪. )employee and department‬‬
‫‪19‬‬
‫‪cont‬‬
‫اذا كان لنوع العالقة صفة و‪, cardinality ratio=1:1‬فيمكن ان نتبع صفة‬
‫العالقة ألى واحد من ال ‪ entity types‬المشاركة فى نوع العالقة‪.‬‬
‫فمثالً الصفة تاريخ تعيين المدير للقسم يمكن ان تكون صفة ل‬
‫‪ department‬او صفة ل ‪.employee‬‬
‫واذا ال ‪ cardinality ratio= 1:N‬او ‪N:1‬‬
‫فصفات نوع العالقة تتبع ل ‪ entity type‬في الجانب ‪ N‬من العالقة ‪.‬‬
‫مثال ‪ :‬أذا كان لدينا مثال صفة تاريخ تعيين الموظف في العالقة ‪works – for‬‬
‫بين)‪ , ) Employee:Department‬و‪ N‬بجانب ال ‪employee E.T‬‬
‫فلذا يجب ان تتبع صفة تاريخ التعيين ل ‪.employee E.T‬‬
‫‪20‬‬
‫‪Cont.‬‬
‫اذا كانت ‪Cardinality ratio =M:N‬‬
‫مثال ‪ :‬عدد الساعات االسبوعية للموظف في العمل في‬
‫المشروع تظل صفة لنوع العالقة ‪ works – for‬بين ال‬
‫‪.employee & project‬‬
‫‪21‬‬
)Weak entity types ‫انواع الكائنات الضعيفة‬
.‫ ليست لها صفة او صفات ثمثل صفة المفتاح‬entity types ‫هي‬
‫ ال تميز اال بعالقتها مع كائنات‬weak entity type ‫الكائنات التي تنتمى لل‬
weak ‫) وال‬owner or parent( ‫ اخر‬entity type ‫اخرى تنتمي ل‬
.)child E.Ts( ‫ يطلق عليها‬E.Ts
Child entity types participation is total participation in
the relation – type between) child) weak entity type and
parent entity type . R.T is called (Identifying R.T)
•
A weak entity has a partial key, which is the set of attributes that
can uniquely identify weak entities that are related to the same
owner entity.
22
In E-R digram:
Identifying relationship type
Partial key
Weak entity type
23
‫مثال ‪ Dependent E.T :‬هو ال ‪WEAK – Entity type‬‬
‫ال يمكن تحديد المكفول اال عن طريق الكفيل وال يمكن ان يكون له مفتاح (فقد‬
‫يحتوي المفتاح علي صفة من الصفات ال ‪ employee‬مثل رقم الموظف ‪+‬‬
‫اسم المكفول)‬
‫وال يوجد مكفول ليس له كفيل ‪.‬‬
‫‪Dependent‬‬
‫‪24‬‬
‫‪M‬‬
‫‪Dependent of‬‬
‫‪1‬‬
‫‪Employee‬‬
Refining the ER diagram for the company
database
ER DIAGRAM – Relationship Types are:
WORKS_FOR,
2. MANAGES,
3. WORKS_ON,
4. CONTROLS,
5. SUPERVISION,
6. DEPENDENTS_OF.
Determine participate entity types and structural constraints for
each relationship type.
1.
25
26
Alternative (min, max) notation for
relationship structural constraints
Specified on each participation of an entity type E in a relationship
type R
Specifies that each entity e in E participates in at least min and at
most max relationship instances in R
Default(no constraint): min=0, max=n (signifying no limit)
Must have minmax, min0, max 1
Derived from the knowledge of mini-world constraints
Examples:
– A department has exactly one manager and an employee can
manage at most one department.
Specify (0,1) for participation of EMPLOYEE in MANAGES
Specify (1,1) for participation of DEPARTMENT in MANAGES
– An employee can work for exactly one department but a
department can have any number of employees.
Specify (1,1) for participation of EMPLOYEE in WORKS_FOR
Specify (0,n) for participation of DEPARTMENT in WORKS_FOR
27
The (min,max) notation for relationship
constraints
Read the min,max numbers next to the entity type and looking
away from the entity type
28
COMPANY ER Schema Diagram using (min,
max) notation
29
Summary of notation for ER diagrams
30
Some of the Currently Available
Automated Database Design Tools
COMPANY
TOOL
FUNCTIONALITY
Embarcadero
Technologies
ER Studio
Database Modeling in ER and IDEF1X
DB Artisan
Database administration, space and security
management
Oracle
Developer 2000/Designer 2000
Database modeling, application development
Popkin
Software
System Architect 2001
Data modeling, object modeling, process modeling,
structured analysis/design
Platinum
(Computer
Associates)
Enterprise Modeling Suite:
Erwin, BPWin, Paradigm Plus
Data, process, and business component modeling
Persistence
Inc.
Pwertier
Mapping from O-O to relational model
Rational (IBM)
Rational Rose
UML Modeling & application generation in C++/JAVA
Resolution Ltd.
Xcase
Conceptual modeling up to code maintenance
Sybase
Enterprise Application Suite
Data modeling, business logic modeling
Visio
Visio Enterprise
Data modeling, design/reengineering Visual Basic/C++
31
•Read section 3.9
32
Please Be
attention!!!!!!!
Additional lecture on
Thursday (2-4)
33
Good bye
chapter
THREE
34
‫)‪Quiz (2‬‬
‫•‬
‫ارسم الـ‪Diagram ER‬‬
‫–‬
‫–‬
‫–‬
‫–‬
‫–‬
‫‪35‬‬
‫للمتطلبات ادناه وهي تمثل قاعدة بيانات لالفالم في السودان‪.‬‬
‫الفيلم ) ‪ ( Movie‬يميز باسمه وتاريخ عرضه وله مدة عرض معينة وله شركة قامت بانتاجه وله‬
‫نوعية معينة ( دراما ‪ ،‬كوميديا ‪. )...‬‬
‫أي فيلم له عدد من المخرجين وعدد من الممثلين وله علي االكثر إثنين من الممثلين يقومون بالدور‬
‫الرئيسي في الفيلم‪.‬‬
‫الممثل ) ‪ ( Actor‬يمكن ان يميز باسمه وتاريخ ميالده ويمكن ان يمثل في اكثر من فيلم وأي ممثل‬
‫يجب ان يكون له دور في فيلم واحد علي االقل وهذا الدور اما ان يكون دور عادي ( تمثيل ) او دور‬
‫رئيسي‪.‬‬
‫المخرج أيضا ً يميز بأسمه ويسجل تاريخ ميالده ويجب ان يخرج فيلم واحد علي االقل ‪ .‬يمكن للمخرج‬
‫ايضا ً أن يكون ممثالً في أي فيلم او االفالم التي قام بإخراجها‪.‬‬
‫الشركات التي تقوم باالنتاج لها إسم وعنوان وال يمكن لشركتين ان تحمالن نفس االسم ويمكن ان يكون‬
‫للشركة اكثر من موقع داخل وخارج السودان‪.‬‬