بسم الله الرحمن الرحيم Lecture( 6) Data Modeling Using the Entity-Relationship...
-
Upload
johnathan-york -
Category
Documents
-
view
218 -
download
0
Transcript of بسم الله الرحمن الرحيم Lecture( 6) Data Modeling Using the Entity-Relationship...
الرحيم الرحمن الله الرحيم بسم الرحمن الله بسم
Lecture( Lecture( 66))
Data Modeling Using the Data Modeling Using the Entity-Relationship (ER) Entity-Relationship (ER)
ModelModel11
العالقة نوع العالقة درجة نوع (Degree)Degree درجة(Relationship type(Relationship type
الـ عدد الـ هي عدد .typestypes EntityEntity هي العالقة نوع في .المشاركة العالقة نوع في المشاركة
(Number of participant Entity type into(Number of participant Entity type into relationship type)relationship type)
العالقة : نوع درجة العالقة : مثال نوع درجة works – forworks – for = = 22مثال
22
االولي الدرجة من العالقة االولي نوع الدرجة من العالقة ::نوعبـ( بـ( تسمي تسمي
))Recursive relationship typeRecursive relationship type (هذا في هذا) والعالقة في والعالقةالـ نفس كائنات بين تكون الـ النوع نفس كائنات بين تكون Entity typeEntity typeالنوع
. العالقة نوع في .المشارك العالقة نوع في المشارك-: االولي الدرجة من لعالقة :-مثال االولي الدرجة من لعالقة مثال
R .T: SupervisionR .T: Supervisionاو علية يشرف آخر موظف له موظف او كل علية يشرف آخر موظف له موظف كل
( ال( أن نجد ولذا ) يرأسه ال( أن نجد ولذا ال Employee E.TEmployee E.Tيرأسه ال هي هيE .TE .T العالقة في المشاركة العالقة الوحيدة في المشاركة Supper Supperالوحيدة
visionvision
33
e1 supervisor of e2e1 supervisor of e2
e2 supervised by e1e2 supervised by e1
(all participating entity In R.T belong to only one E.T) (all participating entity In R.T belong to only one E.T)
e1
e2
e3
r1
r2
44
الدرجةالثالثة :-( من العالقة الدرجةالثالثة :-( نوع من العالقة TernaryTernary((نوع
Number of participate Entity – types In to Number of participate Entity – types In to R.T = 3R.T = 3
55
مثالمثالfather
mother
parent child
f1
m1
r1 c1
66
) الثانية الدرجة من العالقات ( انواع الثانية الدرجة من العالقات Binary Binary((انواعRelationship typesRelationship types::
في ( يتم العالقات قيود معظم تطبيق لذا العالقات انوع اشهر في ( من يتم العالقات قيود معظم تطبيق لذا العالقات انوع اشهر من ( الثنائية ) العالقات الثنائية العالقات
77
العالقات ( انواع العالقات (قيود انواع Relationship types Relationship typesقيود
ConstraintsConstraints ))بعض لها العالقات انواع معظم ان نجد الحقيقي العالم بعض من لها العالقات انواع معظم ان نجد الحقيقي العالم من
المثال . ( في نجد فمثال الشروط او المثال . (القيود في نجد فمثال الشروط او كل) companycompanyالقيود كل) ان انشرط يعتبر وهذا فقط واحد قسم في يعمل ان يجب شرط موظف يعتبر وهذا فقط واحد قسم في يعمل ان يجب موظف
والقسم . الموظف بين العالقة نوع والقسم .في الموظف بين العالقة نوع فيال علي تطبيقها يمكن القيود من نوعين ال وهنالك علي تطبيقها يمكن القيود من نوعين :- :-R.TsR.Tsوهنالك
11- Cardinality Ratio Constraints.- Cardinality Ratio Constraints.2- Participation Constraints 2- Participation Constraints
ب يعرفان القيدان ب وهذان يعرفان القيدان وهذان
structural constraints of relationship typesstructural constraints of relationship types
88
ContCont..
11-cardinality ratio constraints:--cardinality ratio constraints:-
ال تحديد ال ويتم تحديد للعالقة للعالقة ratioratio CardinalityCardinalityويتمال ( عدد بتحديد ال (الثنائية عدد بتحديد relationship relationshipالثنائية
InstancesInstances) (فيها يشارك فيها) (والتي يشارك participant participantوالتيentityentity .(.(
((Specifies the relationship type instances that Specifies the relationship type instances that an entity can participate in)an entity can participate in)
99
العالقة: العالقة: مثال Department : EmployeeDepartment : Employeeبين بين works – forworks – forمثال
Cardinality ratio = 1: N (N zero or more)Cardinality ratio = 1: N (N zero or more)
One: ManyOne: Many
في ذلك في ويوضح ذلك كاالتي :كاالتي :E .R diagramE .R diagramويوضح
Employee1Department N Works-for
1010
ContCont..
Possible cardinality ratios for binary R.T s:Possible cardinality ratios for binary R.T s:1: N, N: 1, 1: 1, M: N1: N, N: 1, 1: 1, M: N
One :Many , Many : One , One :One, Many : ManyOne :Many , Many : One , One :One, Many : Many
ل ل مثال : : N:1N:1مثال
University Student Teach-on 1N
1111
ContCont..
العالقة : نوع العالقة : مثال نوع one : oneone : oneمثال
Department Employee Manages 11
1212
ContCont..
عالقة: لنوع عالقة: مثال لنوع Many : ManyMany : Manyمثال
Project Employee Works-for N M
1313
2. Participation Constraints: (Existence Dependencies):2. Participation Constraints: (Existence Dependencies):
الكائن وجود كان اذا ما لتحديد الكائن وهي وجود كان اذا ما لتحديد entityentityوهينوع عبر اخر بكائن تربطه عالقة علي نوع يعتمد عبر اخر بكائن تربطه عالقة علي يعتمد
) ) R.TR.Tالعالقة (العالقة (
ل ( نوعين ل (هنالك نوعين ))Participation ConstraintsParticipation Constraintsهنالك
1. Total Participation.1. Total Participation.
2. partial Participation.2. partial Participation.
1414
ل ل مثال علي Total ParticipationTotal Participation : :مثال ينص الشركة قانون ان افترضنا علي اذا ينص الشركة قانون ان افترضنا اذاال M إذا معين قسم في يعمل ان يجب موظف أي ال ان M إذا معين قسم في يعمل ان يجب موظف أي ال ال EmployeeEmployeeان
) ال في مشارك كان اذا اال موجود يكون ان (يمكن ال في مشارك كان اذا اال موجود يكون ان works-for works-forيمكنinstancesinstances ( (
(the participation of employee in works-for R.T is total (the participation of employee in works-for R.T is total participation)participation). .
1515
في الكائنات في كل الكائنات ال EmployeeEmployeeكل في ال مشاركة في instancesinstances مشاركةworks – forworks – for , ال في ذلك ال , يوضح في ذلك :E.R diagramE.R diagramيوضح ( كاآلتي ( :بخطين ( كاآلتي ( بخطين
Department Employee Works-for 1N
1616
ل : ل : مثال :- :- partial participatepartial participateمثال
رئيس له الشركة في قسم كل ان رئيس نجد له الشركة في قسم كل ان نجد))managermanager (رؤساء الموظفين لكل ليس رؤساء) ولكن الموظفين لكل ليس ولكن
( ) M فاذا الموظفين من جزء ) اقسام ) M فاذا الموظفين من جزء اقسام( the participation of employee entity type n manages R.T is partial ( the participation of employee entity type n manages R.T is partial participation)participation) employee Manages Department
e1
e2
e3
e4
r1
r2
r3..
d1
d2
d3
.
.
1717
العالقات انواع العالقات صفات انواع صفات
attributes for relationshipattributes for relationship typestypes ( ( ( (
ال ( مثل صفات العالقات إلنواع يكون ان ال (يمكن مثل صفات العالقات إلنواع يكون ان ))Entity typesEntity typesيمكن
الصفه :- ( الصفه :- (امثلة االسبوعية) no of hoursno of hoursامثلة الساعات االسبوعية) عدد الساعات عددالمشروع ( فى المشروع (للموظف فى لنوع) projectprojectللموظف صفة تكون ان لنوع) يمكن صفة تكون ان يمكن
وتوضح) :- وتوضح) :- employee and projectemployee and projectبين ) (بين ) (works- onworks- onالعالقة (العالقة (:E_R diagramE_R diagramفى فى :كاآلتى كاآلتى
Project Employee Works-on N M
No of hours
1818
ContCont..
للقسم المدير تعيين تاريخ للقسم الصفة المدير تعيين تاريخ يكون ) )start datestart date((الصفة ان يكون يمكن ان يمكنللعالقة ( للعالقة (صفة ) .) .employee and departmentemployee and departmentبين) (بين) (managesmanagesصفة
1919
contcont
و صفة العالقة لنوع كان و اذا صفة العالقة لنوع كان ان , cardinality ratio=1:1cardinality ratio=1:1اذا ان , فيمكن فيمكنال من واحد ألى العالقة صفة ال نتبع من واحد ألى العالقة صفة فى entity typesentity typesنتبع فى المشاركة المشاركة
. العالقة .نوع العالقة نوع
صفة تكون ان يمكن للقسم المدير تعيين تاريخ الصفة M صفة فمثال تكون ان يمكن للقسم المدير تعيين تاريخ الصفة M فمثالل departmentdepartmentل ل صفة ل او صفة ..employeeemployeeاو
ال ال واذا N:1N:1او او cardinality ratio= 1:Ncardinality ratio= 1:N واذا
ل تتبع العالقة نوع ل فصفات تتبع العالقة نوع الجانب entity typeentity typeفصفات الجانب في من من NNفيالعالقة .العالقة .
العالقة : في الموظف تعيين تاريخ صفة مثال لدينا كان أذا العالقة : مثال في الموظف تعيين تاريخ صفة مثال لدينا كان أذا مثالworks – forworks – for بين بين Employee:DepartmentEmployee:Department(( , (و) , وNN ال ال بجانب بجانب
employee E.Temployee E.T ل التعيين تاريخ صفة تتبع ان يجب ل فلذا التعيين تاريخ صفة تتبع ان يجب فلذاemployee E.Temployee E.T..
2020
ContCont..
كانت كانت اذا M:NM:N Cardinality ratio Cardinality ratio==اذا
في : للموظف االسبوعية الساعات عدد في : مثال للموظف االسبوعية الساعات عدد مثالالعالقة لنوع صفة تظل المشروع في العالقة العمل لنوع صفة تظل المشروع في العمل
works – forworks – for ال ال بين ..employee & projectemployee & projectبين
2121
الضعيفة الكائنات الضعيفة انواع الكائنات Weak entity Weak entityانواع
typestypes(( . entity typesentity typesهي هي المفتاح صفة ثمثل صفات او صفة لها . ليست المفتاح صفة ثمثل صفات او صفة لها ليست
لل تنتمى التي لل الكائنات تنتمى التي بعالقتها weak entity typeweak entity typeالكائنات اال تميز بعالقتها ال اال تميز الل تنتمي اخرى كائنات ل مع تنتمي اخرى كائنات ) ) owner or parentowner or parentاخر (اخر (entity typeentity typeمع
عليها (weak E.Tsweak E.Tsوال وال عليها (يطلق ).).child E.Tschild E.Tsيطلق
Child entity types participation is total participation in Child entity types participation is total participation in the relation – type betweenthe relation – type between)) child) weak entity type and child) weak entity type and parent entity type . R.T is called (Identifying R.T)parent entity type . R.T is called (Identifying R.T)
A weak entity has A weak entity has a partial keya partial key, , which is the set of attributes that which is the set of attributes that can uniquely identify weak entities that are related to the same can uniquely identify weak entities that are related to the same owner entity. owner entity.
2222
In E-R digram:In E-R digram:
Identifying relationship typeIdentifying relationship type
Weak entity typeWeak entity type
Partial key
2323
ال Dependent E.TDependent E.Tمثال : مثال : ال هو type type WEAK – EntityWEAK – Entityهو
ان يمكن وال الكفيل طريق عن اال المكفول تحديد يمكن ان ال يمكن وال الكفيل طريق عن اال المكفول تحديد يمكن الال ( الصفات من صفة علي المفتاح يحتوي فقد مفتاح له ال ( يكون الصفات من صفة علي المفتاح يحتوي فقد مفتاح له يكون
employeeemployee ( المكفول + اسم الموظف رقم ) مثل المكفول + اسم الموظف رقم مثل
كفيل . له ليس مكفول يوجد كفيل .وال له ليس مكفول يوجد وال
MEmployee 1 Dependent Dependent of
2424
Refining the ER diagram for the company Refining the ER diagram for the company
databasedatabase
ER DIAGRAM – Relationship Types are:ER DIAGRAM – Relationship Types are:
1.1. WORKS_FOR, WORKS_FOR,
2.2. MANAGES,MANAGES,
3.3. WORKS_ON, WORKS_ON,
4.4. CONTROLS, CONTROLS,
5.5. SUPERVISION, SUPERVISION,
6.6. DEPENDENTS_OF.DEPENDENTS_OF.
Determine participate entity types and structural constraints for Determine participate entity types and structural constraints for each relationship type.each relationship type.
2525
2626
Alternative (min, max) notation for Alternative (min, max) notation for relationship structural constraintsrelationship structural constraints
Specified on each participation of an entity type E in a relationship Specified on each participation of an entity type E in a relationship type Rtype RSpecifies that each entity e in E participates in at least Specifies that each entity e in E participates in at least minmin and at and at most most maxmax relationship instances in R relationship instances in RDefault(no constraint): min=0, max=n (signifying no limit)Default(no constraint): min=0, max=n (signifying no limit)Must have minMust have minmax, minmax, min0, max 0, max 11Derived from the knowledge of mini-world constraintsDerived from the knowledge of mini-world constraintsExamples:Examples:– A department has exactly one manager and an employee can A department has exactly one manager and an employee can
manage at most one department.manage at most one department.Specify (0,1) for participation of EMPLOYEE in MANAGESSpecify (0,1) for participation of EMPLOYEE in MANAGESSpecify (1,1) for participation of DEPARTMENT in MANAGESSpecify (1,1) for participation of DEPARTMENT in MANAGES
– An employee can work for exactly one department but a An employee can work for exactly one department but a department can have any number of employees.department can have any number of employees.
Specify (1,1) for participation of EMPLOYEE in WORKS_FORSpecify (1,1) for participation of EMPLOYEE in WORKS_FORSpecify (0,n) for participation of DEPARTMENT in WORKS_FORSpecify (0,n) for participation of DEPARTMENT in WORKS_FOR
2727
The (min,max) notation for relationship The (min,max) notation for relationship constraintsconstraints
Read the min,max numbers next to the entity type and looking away from the entity type
2828
COMPANY ER Schema Diagram using (min, COMPANY ER Schema Diagram using (min, max) notationmax) notation
2929
Summary of notation for ER diagramsSummary of notation for ER diagrams
3030
Some of the Currently Available Automated Database Design Tools
COMPANYTOOLFUNCTIONALITY
Embarcadero Technologies
ER StudioDatabase Modeling in ER and IDEF1X
DB ArtisanDatabase administration, space and security management
OracleDeveloper 2000/Designer 2000Database modeling, application development
Popkin Software
System Architect 2001Data 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.
PwertierMapping from O-O to relational model
Rational (IBM)Rational RoseUML Modeling & application generation in C++/JAVA
Resolution Ltd.XcaseConceptual modeling up to code maintenance
SybaseEnterprise Application SuiteData modeling, business logic modeling
VisioVisio EnterpriseData modeling, design/reengineering Visual Basic/C++3131
•Read section 3.9Read section 3.9
3232
Please Be Please Be attention!!!!!!! attention!!!!!!! Additional lecture on Additional lecture on Thursday (2-4) Thursday (2-4)
3333
Good bye Good bye chapter chapter THREETHREE
3434
Quiz (2)Quiz (2)
الـ • الـ ارسم في Diagram ERDiagram ER ارسم لالفالم بيانات قاعدة تمثل وهي ادناه في للمتطلبات لالفالم بيانات قاعدة تمثل وهي ادناه للمتطلباتالسودان.السودان.
شركة ) ) MovieMovie ( ( الفيلم الفيلم – وله معينة عرض مدة وله عرضه وتاريخ باسمه شركة يميز وله معينة عرض مدة وله عرضه وتاريخ باسمه يميزكوميديا ( ...) . ، دراما معينة نوعية وله بانتاجه كوميديا ( ...) .قامت ، دراما معينة نوعية وله بانتاجه قامت
من – إثنين االكثر علي وله الممثلين من وعدد المخرجين من عدد له فيلم من أي إثنين االكثر علي وله الممثلين من وعدد المخرجين من عدد له فيلم أي. الفيلم في الرئيسي بالدور يقومون .الممثلين الفيلم في الرئيسي بالدور يقومون الممثلين
اكثر ) )ActorActor( ( الممثل الممثل – في يمثل ان ويمكن ميالده وتاريخ باسمه يميز ان اكثر يمكن في يمثل ان ويمكن ميالده وتاريخ باسمه يميز ان يمكنالدور وهذا االقل علي واحد فيلم في دور له يكون ان يجب ممثل وأي فيلم الدور من وهذا االقل علي واحد فيلم في دور له يكون ان يجب ممثل وأي فيلم من
. رئيسي ( ) دور او تمثيل عادي دور يكون ان .اما رئيسي ( ) دور او تمثيل عادي دور يكون ان اماعلي – واحد فيلم يخرج ان ويجب ميالده تاريخ ويسجل بأسمه يميز M أيضا علي المخرج واحد فيلم يخرج ان ويجب ميالده تاريخ ويسجل بأسمه يميز M أيضا المخرج
قام . التي االفالم او فيلم أي في M ممثال يكون أن M ايضا للمخرج يمكن قام . االقل التي االفالم او فيلم أي في M ممثال يكون أن M ايضا للمخرج يمكن االقلبإخراجها.بإخراجها.
نفس – تحمالن ان لشركتين يمكن وال وعنوان إسم لها باالنتاج تقوم التي نفس الشركات تحمالن ان لشركتين يمكن وال وعنوان إسم لها باالنتاج تقوم التي الشركات. السودان وخارج داخل موقع من اكثر للشركة يكون ان ويمكن .االسم السودان وخارج داخل موقع من اكثر للشركة يكون ان ويمكن االسم
3535