Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "بسم الله الرحمن الرحيم."— Presentation transcript:

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

2 Lecture(5) Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model

3 Database Design process
عملية تصميم قاعدة البيانات تحتوي علي الخطوات التالية: 1st step:- Requirements collection and analysis تجميع حاجات المستخدمين وتحليلها.. تنتهي هذه الخطوة بتحديد كل احتياجات المستخدمين (data requirements ( وتحديد كل العمليات المطلوبة علي قاعدة البيانات (Functional requirements) وتشمل العمليات المعرفة بواسطة المستخدمين (User defined operations ) وعمليات الاسترجاع والتحديث by using dataflow diagram ,sequences diagram .....etc

4 2nd step:- Conceptual design:
بمجرد تجميع الاحتياجات وتحليلها ، يشرع المصممون في إنشاء ما يعرف بـ Schema Conceptualلقاعدة البيانات ولإنشاء هذه الخارطة تستخدم احدي نماذج الـ (High-level conceptual data Models) وذلك بوصف البيانات عن طريق استخدام مفاهيم النموذج مثال لذلك الـ (E- R Model). وهذه المفاهيم لا تحتوي علي أي تفاصيل للتطبيق Implementation details)). ولذا تستخدم الـ Schema Conceptualكمرجع للتأكد من أن احتياجات كل المستخدمين مستوفاه في البيانات وان الاحتياجات ليس بها تضارب لأن المصممين يكون تركيزهم فقط علي تصميم خارطة تستوفي كل احتياجات المستخدمين دون التفكير في طريقة التطبيق وتكون الخارطة مفهومة لدي المستخدمين غير المتخصصين.

5 3rd Step: - Implementation of the database, using a commercial DBMS:
في هذه الخطوة يتم تحويل الـ Schema Conceptual من الـ High level conceptual data Model الي Implementation data Model أي الي النموذج المستخدم في ال DBMS المختارة لتطبيق قاعدة البيانات . وهذا التحويل يسمي بـ Data Model Mapping أو Logical design وهذه الخطوة تنتهي بإنشاء خارطة قاعدة البيانات (Database schema) باستخدام النموذج المستخدم في الـ DBMS مثال لذلك: E-R model mapping to Relational Model.

6 Final step:- physical design phase:
أثناءهذه الخطوة يتم تحديد كل تفاصيل التخزين وذلك بتحديد: Access paths, file organization for database file. وهذه الخطوة تنتهي بإنشاء خارطة داخلية لقاعدة البيانات (internal schema) علي التوازي مع كل هذه الخطوات يتم أيضا تصميم البرامج التطبيقية (باستخدام طرق هندسة البرمجيات) وتطبيقها كحركات لقاعدة البيانات (Database Transactions ( See figure bellow:

7 Overview of Database Design Process

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

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

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

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

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

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

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

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

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

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

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

19 Derived Attribute :-

20 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

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

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

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

24 التحديد الإبتدائى لل 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

25 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).

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

27 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 :- )

28 مثال

29 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 علي انها مجموعة من instances ri)) والتي تربط بين ال individual entities (e1, ….en) حيث ((e1, ….en هي كائنات لـ participant entity types) )

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

31

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

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

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

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

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

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

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

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

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

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

42 Cont. مثال لN:1 : 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 1 N

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

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

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

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

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

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


Download ppt "بسم الله الرحمن الرحيم."

Similar presentations


Ads by Google