1 / 27

E_R Diagram Examples

E_R Diagram Examples. Lec4. مثال: قواعد بيانات خاصة ببنك:. كل بنك يعرف برقم البنك، اسم البنك، عنوان البنك. و يكون له عدة فروع. كل فرع يعرف برقم الفرع، و عنوان الفرع. و لديه حسابات و قروض متعددة. كل حساب يعرف برقم الحساب، و نوع الحساب، و الرصيد.

raven
Download Presentation

E_R Diagram Examples

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. E_R Diagram Examples Lec4

  2. مثال:قواعد بيانات خاصة ببنك: كل بنك يعرف برقم البنك، اسم البنك، عنوان البنك. و يكون له عدة فروع. كل فرع يعرف برقم الفرع، و عنوان الفرع. و لديه حسابات و قروض متعددة. كل حساب يعرف برقم الحساب، و نوع الحساب، و الرصيد. كل عميل يعرف برقم التسلسل الاجتماعي ، ورقم الهاتف، والعنوان.و من المطلوب تتبع تاريخ فتح حساب العميل.

  3. E-R Diagram اسم البنك عنوان الفرع رقم البنك العنوان رقم الفرع البنك يحتوي الفرع الهاتف رقم الحساب يحتوي العنوان العميل الحساب الرصيد الاسم فتح حساب نوع الحساب رقم التسلسل الاجتماعي تاريخ فتح الحساب

  4. A DB is designed for a library to manage data of books and borrowing transactions The library contains books which are described by an ISBN, Title, Specialization. Each Book is published by one Publisher and written by many Authors. A publisher is described by name, ID, Address, Fax and Phone number An author is described by name, ID, Address, Fax and Phone number. Each author writes many books. A borrower is described by Card Number, Name, Address. It is required to keep track of date out and due date of each borrowing transaction.

  5. It is required to keep track of date out and due date of each borrowing transaction.

  6. name id PUBLISHER title specia isbn Published by BOOK date out Written by Is borrowed by due date AUTHOR BORROWER card_number id name name

  7. Hospital database requirements • Each Doctor is described by Doc ID, Phone, address, and specialization. Each doctor is allowed to work in only one department. • Each department is described by Dept no, Name, No of doctors and is supervised by a doctor. • Each patient is described by Card number, name, address, and phone. Each patient is assigned to one or more department. It’s required to keep track each admission date. • Each lab is described by LabNo, name. It’s required to keep track any lab service that may be done to the patient.

  8. Solution: Miniworld: Hospital Entities/ Data elements(Attributes) /Data Types Doctor: Department: Patient: Lap:

  9. Relationships: • 1-Each doctor is allowed to work in only one department. • 2-Each department is supervised by a doctor. • 3- Each patient is assigned to one or more department. It’s required to keep track each admission date. • 4-It’s required to keep track any lab service that may be done to the patient.

  10. Primary Keys Doctor: Department: Patient: Lap:

  11. E-r relational ships: Work in Department Doctor علاقة واحد-متعدد علاقة واحد- واحد علاقة متعدد – متعدد علاقة متعدد –متعدد supervised Doctor Department Admission date Department Register patient Service type lab Register patient

  12. :E-R Diagram dept name dept_no no-of doc phone no address specialization docid Work in DEPARTMENT DOCTOR supervised Contain admission date service_type Service PATIENT LAB card no address phone no labno lab name name

  13. كيفية تحويل (E-R diagram) إلى (tables ) جداول في برنامج access: • نحول كل كينونة (entity) إلى جدول (Table). • نحول كل صفة (attribute) إلى عمود (column). • نضيف أي صفة علاقة (attribute-relationship) إلى جدول الكينونة على شكل عمود.

  14. علاقة واحد- واحد ( one-one): • نرى الجدول الذي مفتاحه الرئيسي إجابته بلا و نضعه كمفتاح أجنبي(foreign key) في الجدول الآخر. • نجعل المفتاح الأجنبي في التصميم المفهرس ب ”نعم بدون تكرار“

  15. II.علاقة واحد – متعدد (:(one-many • نجعل المفتاح الرئيسي للكينونة التي من جهة الواحد و نجعلها مفتاح أجنبي في جدول الذي من جهة المتعددة.

  16. III.علاقة متعدد – متعدد (many-many): • نقسم العلاقة لعلاقتين تمثل بعلاقة واحد-متعدد. • ننشأ جدول جديد و يكون اسمه مجمع بين اختصارات جدولي العلاقة و نفصل بين الأسمين ب _ . • نضيف المفاتيح الرئيسية لجدولي العلاقة في الجدول الجديد كأعمدة و نضيف أي صفة علاقة بين جدولي العلاقة إذا وجد في الجدول الجديد كاعمود. • المفتاح الرئيسي للجدول الجديد هو عبارة عن مفتاح مجمع بين المفاتيح الرئيسية لجدولي علاقة متعدد-متعدد و يكون في نفس الوقت مفتاح أجنبي للعلاقتين الجديدتين التي تكون بين جداول علاقة متعدد- متعدد و الجدول نفسه . • نكون علاقتي واحد-متعددة بين جدولي العلاقة متعدد-متعدد بربط علاقتين واحد-متعدد مرة من الجدول الأول لعلاقة متعدد-متعدد وبين الجدول الجديد و مرة أخرى من الجدول الثاني و الجدول الجديد. • و يكون جهة الواحد في جداول علاقة متعدد-متعدد و جهة متعدد في الجدول الجديد.

  17. ملاحظات: • عدد الجداول في الAccess ممكن تكون (أكبر من أو يساوي) عدد الكينونات في ال E_R Diagram. • عند عمل أي علاقة نسحب من الPK إلى الFK. • لانشاء علاقة 1-1 فقط نعدل خاصية الفهرسة للFK الى نعم تكرار غير مقبول. • لإنشاء علاقة M-M في الAccess تفك العلاقة الى علاقتين (1-M) و(1-M) ويكون ال 1 من ناحية الجداول الرئيسية والM من ناحية الجدول الجديد. • صيغة العلاقة الموجودة في علاقة(1-1)أو (1-M) في الE_R Diagramتضاف في الجدول مع الFK. • إذا كانت العلاقة دائرية نعاملها على أنها جدولين ونأخذ ال PKمن احد الجدولين ونضيفه في الأخر.

  18. Example 1:Hospital database : • Each Doctor is described by Doc ID, Phone, address, and specialization. Each doctor is allowed to work in only one department. • Each department is described by Dept no, Name, No of doctors and is supervised by a doctor. • Each patient is described by Card number, name, address, and phone. Each patient is assigned to one or more department. It’s required to keep track each admission date. • Each lab is described by Lab No, name. It’s required to keep track any lab service that may be done to the patient.

  19. Doctor: Department:

  20. Patient: Lap:

  21. Department_Patient: Lap_Patient:

  22. Relationships:

  23. Example 2: COMPANY Database • Requirements of the Company (oversimplified for illustrative purposes) • The company is organized into DEPARTMENTs. Each department has a name, number and an employee who manages the department. We keep track of the start date of the departmentmanager. • Each department controls a number of PROJECTs. Each project has a name, number and islocated at a single location.

  24. Example COMPANY Database (Cont.) • We store each EMPLOYEE’s social security number, address, salary, sex, and birthdate. Each employee works for one department but may work on several projects. We keep track of the number of hours per week that an employee currently works on each project. We also keep track of the direct supervisor of each employee.

  25. Relationships:

  26. Department • project

  27. Employee • project_Employee

More Related