Presentation is loading. Please wait.

Presentation is loading. Please wait.

Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39021 Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.)

Similar presentations


Presentation on theme: "Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39021 Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.)"— Presentation transcript:

1 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39021 Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.) Data modeling Entity-relationship model -Entity types -strong entities -weak entities -Relationships among entities -Attributes - attribute classification -Constraints -cardinality constraints -participation constraints ER-to-Relation-mapping

2 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39022 Entity-relationship model (ER model) P. 41-2: “This model and its variations are frequently used for the conceptual design of database applications, and many database design tools employ its concepts.” ER model: is used to create a conceptual data model that reflects all the user data requirements. It includes detailed descriptions of entity types, relationships, and constraints no implementation details so can be used for communication with non-technical users

3 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39023 Example The company database keeps track of a company’s employees, departments, and projects: Requirements: concerning the department: 1.company is organized into departments 2.a department has a unique name, a unique number, and a specific employee is its’ manager 3.we track the start date for the manager function 4.a department may be in several locations 5.a department controls a number of projects concerning the project: 6.a project has a unique name, a unique number, and is in a single location

4 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39024 example continued concerning the employee: 7.each employee has a name, social insurance number, address, salary, sex, and birth date 8.an employee is assigned to one department but may work on several projects which are not necessarily controlled by the same department 9.we track the number of hours per week that an employee works on each project 10.we keep track of the direct supervisor of each employee 11.we track the dependents of each employee (for insurance purposes) concerning the dependent: 12.we record each dependent’s first name, sex, birth date, and relationship to the employee

5 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39025 The entities: employee department project dependent

6 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39026 The entities: bdate ssn name lname minit fname sex address salary birthdatenamesex relationship name numberlocation name numberlocation employee department project dependent

7 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39027 With relationships: employee department project dependent works for manages works on dependents of controls supervision 1 N N 1 NM 1 N 1 1 N 1 supervisor supervisee partial constraint total constraint

8 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39028 employee department project dependent With attributes, etc: works for manages works on dependents of controls supervision bdate ssn name lname minit fname sex address salary birthdatenamesex relationship name numberlocation name numberlocation number of employees startdate hours 1 1 1 N supervisor supervisee Figure 3.2 P.46 M N 1 1 N N degree 1 N

9 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39029 Let’s consider a university environment: At a high level, we need to: offer courses register students assign instructors to courses assign grades anything else?

10 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390210 Concepts (you should understand) Attribute classification simple attribute multivalued attribute composite attribute complex (nested) attributes Attribute storage stored & derived attribute null values not applicable, unknown, missing key attribute domain

11 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390211 Relationships degree of a relationship recursive relationship role names constraints cardinality: m-n, 1-n, 1-1 participation: partial, total (existence dependency) Concepts (you should understand)

12 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390212 Entities entity type strong entity -key attribute -entity has a key attribute or a combination of attributes which can be used as a key. weak entity No key attributes. Entities belonging to a weak entity type are identified by being related to specific entities from another entity type in combination with some of their attribute values. - identifying owner - identifying relationship - partial key

13 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390213 Instructors: let’s assume this classification includes instructors, professors, part-time people (at least for now). These people have SINs, employee numbers, names, addresses, offices, phones,... instructor SIN office address employee no name phonedegree

14 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390214 instructor SIN office address employee no name phone Is there a key attribute? What are the domains? Can any attribute be null? Is any attribute composite, derived, complex, multivalued? Is this a weak entity or a strong entity? Should department be an attribute? degree

15 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390215 Departments: obviously instructors are employed by the University and associated with a department A department has a name, number, office, chair,... department Dnumber chair phone name office

16 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390216 department Dnumber chair phone name office Should chair be an attribute, or is there a relationship between two entity types? Is there a key attribute? What are the domains? Can any attribute be null? Is any attribute composite, derived, complex, multivalued?

17 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390217 department Employs relationship: If we assume the relationship between department and instructor is 1:N then we only associate each department with a single instructor, but we associate any number of instructors with a single department instructor employs 1N 1:N is the cardinality of the relationship the relationship is of degree 2; it is a binary relationship Both entities are considered strong entities

18 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390218 Consider some instances department employs instructor d1 d2 d3 e1 e2 e3 e4 e5 e6 e7

19 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390219 department Chair relationship: A department has a chair who has special responsibilities. One person (instructor) is designated as such. instructor chair 11 1:1 is the cardinality of the relationship the relationship is of degree 2; it is a binary relationship.

20 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390220 Continuing the discussion on data modeling Weak entity again Data analysis (at entity instance level) Mapping ER to relational database schema ER model comparison

21 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390221 Weak entity types a weak entity does not have a key of its own - may have a partial key the identifying relationship will have total participation for the weak entity e.g. consider courses and sections at UWinnipeg

22 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390222 Consider courses and course sections In the fall and winter we have: 91.1453/3-001 F Intro Computers staff MW 16:30-17:45 3C13.. 91.1453/3-002 W Intro Computers staff MW 16:30-17:45 3C13.. 91.1453/3-050 F Intro Computers staff T 18:00-21:00 3C13.. 91.1453/3-051 W Intro Computers staff T 18:00-21:00 3C13.. Section numbers are 001, 002, 050, 051, … Sections have a section number, a term, days and times, …

23 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390223 Consider courses and course sections course 1N Offered-in Section no term meeting Section is a weak entity - it has a discriminator (partial key), section number. Section totally participates in the offered in relationship PK (primary key) of Section is … (offered_in is an identifying relationship) Is meeting multivalued? course no name credit hours description section

24 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390224 Data analysis: instructorcourse textbook uses teaches m m n n Note that teaches and uses are both binary relationships: we expect situations where a specific Instructor teaches a specific Course, and where a specific Course uses a specific text

25 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390225 Consider instances instructorcoursetextbook

26 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390226 Jones and Smith are Instructors instructor course Courses offered are Intro to X, Intro to Y, Z, Advanced X, Advanced Y jones smith Intro to X Z Intro to Y Advanced X Advanced Y

27 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390227 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y Consider instances of Instructor teaches Course

28 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390228 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y There is a relationship between Instructor Jones and Course Intro to X

29 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390229 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y This line connects the three dots

30 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390230 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y Jones teaches Advanced X

31 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390231 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y Jones teaches Advanced X Smith teaches Intro to Y

32 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390232 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y Jones teaches Advanced X Smith teaches Intro to Y Smith teaches Advanced Y

33 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390233 instructor teachescourse Jones teaches Intro to X jones smith Intro to X Z Intro to Y Advanced X Advanced Y Jones teaches Advanced X Smith teaches Intro to Y Smith teaches Advanced Y Smith and Jones teach Z together There are two relationships: one between Jones and Z; the other between Smith and Z

34 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390234 instructor teachescourse usestextbook jones smith Intro to X Z Intro to Y Advanced X Advanced Y UML distilled The mythical man-month Now let us examine Course uses Textbook Suppose we have two textbooks: The mythical man-month, and UML distilled

35 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390235 instructor teachescourse usestextbook jones smith Intro to X Z Intro to Y Advanced X Advanced Y UML distilled The mythical man-month Intro to Y uses The mythical man-month

36 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390236 instructor teachescourse usestextbook jones smith Intro to X Z Intro to Y Advanced X Advanced Y UML distilled The mythical man-month Z uses both texts

37 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390237 Let’s jump ahead to see what relations we eventually create Section 9.1: ER-to-Relational mapping 1. Create a relation for each strong entity type 2. Create a relation for each weak entity type include primary key of owner (an FK - foreign key) owner’s PK + partial key becomes PK 3. For each binary 1:1 relationship choose an entity and include the other’s PK in it as an FK. Include any attributes of the relationship 4. For each binary 1:n relationship, choose the n-side entity and include an FK w.r.t the other entity. Include any attributes of the relationship

38 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390238 5. For each binary M:N relationship, create a relation for the relationship include PKs of both participating entities and any attributes of the relationship PK is the concatenation of the participating entity PKs 6. For each multivalued attribute create a new relation include the PK attributes of the entity type PK is the PK of the entity type and the multivalued attribute 7. For each n-ary relationship, create a relation for the relationship include PKs of all participating entities and any attributes of the relationship PK may be the concatenation of the participating entity PKs

39 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390239 employee department project dependent works for manages works on dependents of controls supervision 1 N N 1 NM 1 N 1 1 N 1 supervisor supervisee

40 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390240 division group c composed of div composed of dep composed of department 1 1 1 n n n Consider the following requirements (very typical situation) A company may be composed of Divisions, each of which may be composed of Departments, each of which may be composed of Groups. We could model this as follows: company

41 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390241 company division group c composed of div composed of dep composed of department 1 1 1 n n n It fits the requirements, but it is not flexible it does not accommodate any new groupings it does not allow the company to grow/change it is very rigid => it is a static model

42 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390242 Consider the following model it is flexible it does accommodate any new groupings it does allow the company to grow/change it is not rigid => it is a dynamic model but not all constraints are implied in the model => we would need supporting application code. What are these constraints? lower_level higher_level m n organization composed of higher_level

43 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390243 Consider the following model it is flexible, it does accommodate any new groupings, it does allow the company to grow/change, it is a dynamic model again not all constraints are implied in the model => we would need supporting application code. What are these constraints? m n organization composed of organization type example of org composed of m n mn lower_level higher_ level higher_level lower_level Constraint-des

44 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390244 organization org-name Dell sell-division... Composed-of org Dell sub-org Sell-division... Production-division Example-of org Dell sell-division org-type company... division organization-type org-type company division... org-composed-of org-type company division... sub-org-type division department constraint 1:n

45 Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-390245 Other common situations: How would we model bill-of-materials? How would we model reporting relationships? How would we model geographical relationships? How would we model procedures and activities? How would we model purchase orders? How would we model documents? … with indexes? … with versions?


Download ppt "Data modeling using the entity-relationship model Sept. 2012Yangjun Chen ACS-39021 Outline: Data modeling using ER-model (Chapter 3 - 3rd, 4th, 5th ed.)"

Similar presentations


Ads by Google