1 / 52

بسم الله الرحمن الرحيم

بسم الله الرحمن الرحيم. Lecture( 5). ENTITY RELATIONSHIP MODEL نموذج الكائنات المرتبطة. Popular high_ level conceptual data Model , developed by Peter Chen (1976). المفاهيم الأساسية للنموذج :- 1. الكائنات Entities 2. الصفات Attributes 3 . العلاقات Relationships.

raymondm
Télécharger la présentation

بسم الله الرحمن الرحيم

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. بسم الله الرحمن الرحيم Lecture( 5)

  2. ENTITY RELATIONSHIP MODELنموذج الكائنات المرتبطة Popular high_ level conceptual data Model , developed by Peter Chen (1976). المفاهيم الأساسية للنموذج :- 1. الكائنات Entities 2. الصفات Attributes 3. العلاقات Relationships

  3. ال Schema conceptual تكون علي شكل Diagram يسمي ب E-R diagram ويكون ذلك باستخدام أشكال معينة (NotationsE-R diagram) ((page 80 لكل المفاهيم والقيود.

  4. الكائنات والصفات الكائن هو ال (Basic object) في نموذج الكائنات تعريف ال Entity (الكائن) : وهواى شئ موجود في العالم الحقيقي ولا يعتمد وجوده علي وجود شئ أخر . "Thing In real world with an Independent existence ” وجود الكائن أما أن يكون فيزيائيا (physical existence) ومثال لذلك Car ، person ، student ، house أو يكون مفاهيمي (Conceptual existence) ومثال لذلك Company ، Course ، jop

  5. لكل كائن عدد من الصفات (Attributes) تستخدم لوصفه (Properties to describe entity) مثال :- Entity : Employee الصفات :- Name, SSN ,Sex , sal , address , age وكل صفة من هذه الصفات تكون لها قيمة (Value) لكل كائن خاص (particular Entity) مثال :- E1هو كائن خاص (particular Entity) قيم صفاته: Ali , 46 , M , 30.000 , Omdurman , 40 Attribute Values become a major part of data in the DB))

  6. (Attribute types) أنواع الصفات ) :Atomic attributeالصفة الصماء( صفة لا يمكن تجزئتها لأكثر من صفة . الصفة غير الصماء( Composite attribute ):- صفة يمكن تجزئتها لأكثر من صفةوكل صفة مستقلة عن الاخري وتسمى الصفات المجزئة ب Sub parts)) . مثال:- Address Office Address state Street No City Home Address

  7. الصفة وحيدة القيمة: ( Single Valued Attribute)- صفة لها قيمة واحدة فقط لكل كائن خاص. مثال :- الصفة Age في الكائن Employee كل Employee له عمر واحد فقط . الصفة متعددة القيم -:( Multivalued attribute) صفة لها اكثر من قيمةللكائن الخاص. مثال : فى الكائن Car الصفة color قد يكون لعربة معينة (particular entity) اكثر من لون. الصفة المركبة complex attributes)) :للقراءة من الكتاب صفحة (48).

  8. الصفة المحسوبة(Derived attribute) :- صفة قيمتها محسوبة من صفة او (صفات) اخرى (stored attribute). مثال :- Derived attribute (age), stored attribute (Birth date) Null value:- بعض الصفات قد تحمل القيمة Null لبعض الكائنات الخاصة وهي تعني قيم غير معروفة او غير موجودة Null = unknown. مثال : الصفة College certificate لشخص لا يحمل مؤهل جامعي تحمل القيمة Null .

  9. Entity Type نوع الكائن((Entity type :- مجموعة من الكائنات لها نفس الصفات. (Set or Collection of the entities that have the same attributes) قاعدة البيانات تتكون من عدة من ال ( Entity types) وكل Entity type يعرف باسمه وصفاته.

  10. Entity Type name :- employee company Attributes:- Name, age , salary Name, No, president E1 Ali , 30,30000 E2 Ahmed,40,50000 ……. ……… C1 Sisco,ab60,omer C2 Nilegroup,ac360,ali …….. ……... Entity sets (extension) The collection of all entities of a particular entity type in the database at any point in time is called an entity set.  Entity type & entity set have the same name.

  11. E R_ Diagram Notation شكل Entity Type في ال E R_ DIAGRAM (علي شكل مستطيل) وبداخله إسم ال Entity Type . صفات ال Entity Type تكون علي شكل بيضاوي متصلة معه بخطوط مستقيمة age salary name employee

  12. أشكال انواع الصفات Multivalued attribute:- Composite attribute : Sub parts attribute Composite attribute name

  13. Derived Attribute :-

  14. Key attributes of an entity type من القيود الهامة جدا للكائنات المكونة ل Entity – type وهو ان كل Entity – type له صفة تمثل صفة المفتاح Key attribute ولهذه الصفة قيمة مختلفة لكل كائن في ال E.T ويعرف هذا القيد ب Uniqueness Constraint on attributes)( Key attribute In E.R Diagram:- الصفة التي تمثل صفة المفتاح يمكن ان تكون صفة واحدة (Simple Key) او تتكون من عدة صفات من ال E.T (Composite Key). ويمكن ان يكون ل E.T اكثر من صفه (كل صفة علي حدا) يمكن ان تمثل صفة المفتاح , وقد لا يكون ل E.T أي صفة تمثل صفة المفتاح ويسمي في هذه الحالة بال E.T الضعيف (weak Entity type). Key attribute name

  15. Value sets (Domain) أي صفة من صفات ال E.T لها مجموعة من القيم التي يمكن ان تاخذها تسمى بالمجال (Domain or Value sets ) لهذه الصفة . Value sets can’t be displayed In E-R diagram (Value sets (Domain ) + Key ) called attribute constraints in E-R model.

  16. بسم الله الرحمن الرحيم Lecture( 6)

  17. An Example Database Application • Company DB requirements: • The company has several departments. Each department has a unique name, a unique number, and a particular employee who manages the department. we keep track of the start date when the employee began managing the department. A department may have several locations. • A department controls a number of projects, each of which has a unique name, a unique number, and a single location.

  18. Cont. We store each employee's name, social security number, address, salary, sex, and birth date. An employee is assigned to one department but may work on several projects. We keep track of the number of hours per week that an employee works on each project. We want to keep track of the dependents of each employee for insurance purposes. We keep each dependent ‘s first name ,sex, birth date, and relationship to the employee.

  19. التحديد الإبتدائى لل E.Ts والصفات لقاعدة البيانات Company Four Entity types :- 1. Department Attributes: Name , Number, Location , Manager , Manager start date . Location :- Multivalued attribute . Name, Number: - Separate Key Attribute (أي صفة منهم يمكن ان تمثل المفتاح) 2. Project:- Attributes: - Name, Number, Location, Controlling Departments. (أي صفة منهم يمكن ان تمثل صفة المفتاح) Name or Number

  20. Cont. 3. Employee :- Attributes: - Name, SSN, Sex, Address, Salary, Birth date, Department, Supervisor. Name and Address: - composite Attributes . 4. Dependant Attributes: Employee, Dependant Name, Sex, Birth date, Relation (Employee).

  21. هنالك شرط لم يوضح في ال E.Ts وهو ان كل موظف يعمل في اكثر من Project وتحسب له عدد الساعات الاسبوعيه في كل Project هذه الصفة لها خيارين اما توضع ك (Multivalued Composite Attribute ) ضمن صفات ال Employee E.T كالأتي :- Workers on (project , Hours)} ){ أو ضمن صفات ال project كالاتي:- { Workers(employee, hours) }

  22. Relationships انواع العلاقات( Relationship types) -: Relationship type R among n entity types E1,.….,En defined as a set of associations (or relationship set) among entities from these types. Relationship: types:R.Ts)) Remark :- )

  23. مثال

  24. R: Relationship type (or relationship set ) E1 , E2: Entity types , Each of one is said to participate in relationship type R r1 , r2 , r3,…,r7 : relationship instances (or set ). (individual entities) (e1, e2, e3,…, e7) and (e'1, e'2,e'3) are said to participate into relationship instances . ولذا يمكن تعريف الـ relationship type علي انها مجموعة من instancesri)) والتي تربط بين ال individual entities (e1, ….en)حيث ((e1, ….en هي كائنات لـ participant entity types) )

  25. مثال : Works- for : Relationship type Participant entity types: Employee and Department أي أن العلاقة بين Department , Employee) ) (الموظف والقسم الذي به)

  26. R.T in E-R diagram University Student Teach-on Std no std name University name

  27. درجة نوع العلاقةDegree)(Relationship type هي عدد الـ typesEntity المشاركة في نوع العلاقة. (Number of participant Entity type intorelationship type) مثال : درجة نوع العلاقة 2 = works – for

  28. نوع العلاقة من الدرجة الاولي : (تسمي بـ (Recursive relationship type) والعلاقة في هذا النوع تكون بين كائنات نفس الـ Entity type المشارك في نوع العلاقة. مثال لعلاقة من الدرجة الاولي:- R .T: Supervision كل موظف له موظف آخر يشرف علية او (يرأسه) ولذا نجد أن ال Employee E.T هي ال E .T الوحيدة المشاركة في العلاقة Supper vision

  29. e1 supervisor of e2 e2 supervised by e1 (all participating entity In R.T belong to only one E.T) r1 e1 r2 e2 e3

  30. نوع العلاقة من الدرجةالثالثة :-( (Ternary Number of participate Entity – types In to R.T = 3

  31. مثال father parent child f1 r1 c1 mother m1

  32. انواع العلاقات من الدرجة الثانية( (Binary Relationship types: من اشهر انوع العلاقات (لذا تطبيق معظم قيود العلاقات يتم في العلاقات الثنائية)

  33. قيود انواع العلاقات (Relationship types Constraints ( من العالم الحقيقي نجد ان معظم انواع العلاقات لها بعض القيود او الشروط . فمثلا نجد في المثال (company) ان كل موظف يجب ان يعمل في قسم واحد فقط وهذا يعتبر شرط في نوع العلاقة بين الموظف والقسم . وهنالك نوعين من القيود يمكن تطبيقها علي ال R.Ts :- 1- Cardinality Ratio Constraints. 2- Participation Constraints وهذان القيدان يعرفان ب structural constraints of relationship types

  34. Cont. 1-cardinality ratio constraints:- ويتم تحديد ال ratioCardinality للعلاقة الثنائية بتحديد عدد ال (relationship Instances) والتي يشارك فيها (participant entity ). (Specifies the relationship type instances that an entity can participate in)

  35. مثال: العلاقة works – for بين Department : Employee Cardinality ratio = 1: N (N zero or more) One: Many ويوضح ذلك في E .R diagram كالاتي : Department Works-for N Employee 1

  36. Cont. Possible cardinality ratio for binary R.T s: 1: N, N: 1, 1: 1, M: N One :Many , Many : One , One :One, Many : Many مثال لN:1 : University Student Teach-on N 1

  37. Cont. مثال : نوع العلاقة one : one Department Employee Manages 1 1

  38. Cont. مثالب : لنوع علاقة Many : Many Project Employee Works-for M N

  39. 2. Participation Constraints: (Existence Dependencies): وهي لتحديد ما اذا كان وجود الكائن entity يعتمد علي علاقة تربطه بكائن اخر عبر نوع العلاقة (R.T) هنالك نوعين ل (Participation Constraints) 1. Total Participation. 2. partial Participation.

  40. مثال ل :Total Participation اذا افترضنا ان قانون الشركة ينص علي ان أي موظف يجب ان يعمل في قسم معين إذاً ال Employee لا يمكن ان يكون موجود الا اذا كان مشارك في ال(works-for instances) (the participation of employee in works-for R.T is total participation).

  41. كل الكائنات في Employee مشاركة في ال instances works – for ,يوضح ذلك في ال E.R diagram (بخطين) كالآتي: Department Employee Works-for N 1

  42. مثال : ل partial participate :- نجد ان كل قسم في الشركة له رئيس (manager) ولكن ليس لكل الموظفين رؤساء اقسام (جزء من الموظفين) فاذاً ( the participation of employee entity type n manages R.T is partial participation) employee Manages Department e1 e2 e3 e4 r1 r2 r3 . . d1 d2 d3 . .

  43. صفات انواع العلاقات attributes for relationshiptypes) ) يمكن ان تكون للعلاقات صفات مثل ال (Entity types) امثلة :- الصفه (no of hours) عدد الساعات الاسبوعية للموظف فى المشروع (project) يمكن ان تكون صفة العلاقة (works- on ) بين (employee and project) :- وتوضح فى E_R diagram كالآتى: No of hours Project Employee Works-on M N

  44. Cont. الصفة تاريخ تعيين المدير للقسم(start date ) يمكن ان يكون صفة للعلاقة (manages) بين (employee and department) .

  45. 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.

  46. Cont. اذا كانت العلاقة =M:N Cardinality ratio مثال : عدد الساعات الاسبوعية للموظف في العمل في المشروع تظل صفة العلاقة works – for بين ال employee & project.

  47. انواع الكائنات الضعيفة Weak entity types) هي entity types ليست لها صفة او صفات ثمثل صفة المفتاح. الكائنات التي تنتمى لل weak entity type لا تميز الا بعلاقتها مع كائنات اخرى تنتمي ل entity type اخر (owner or parent) وال weak E.Ts يطلق عليها (child 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)

  48. In E-R digram: Identifying relationship type Weak entity type

  49. مثال : Dependant E.T هو الtype WEAK – Entity لا يمكن تحديد المكفول الا عن طريق الكفيل ولا يمكن ان يكون له مفتاح (فقد يحتوي المفتاح علي صفة من الصفات ال employeeمثل رقم الموظف + اسم المكفول) ولا يوجد مكفول ليس له كفيل . M 1 Employee Dependant Dependant of

More Related