Presentation is loading. Please wait.

Presentation is loading. Please wait.

Entity Relationship (ER) Modeling

Similar presentations


Presentation on theme: "Entity Relationship (ER) Modeling"— Presentation transcript:

1 Entity Relationship (ER) Modeling
Chapter 4 Entity Relationship (ER) Modeling Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

2 In this chapter, you will learn:
The main characteristics of entity relationship components How relationships between entities are defined and refined and how those relationships are incorporated into the database design process How ERD components affect database design and implementation That real-world database design often requires the reconciliation of conflicting goals <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

3 The Entity Relationship (ER) Model
ER model forms the basis of an ER diagram ERD represents conceptual database as viewed by end user ERDs depict database’s main components: Entities Attributes Relationships Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

4 Entities Refers to entity set and not to single entity occurrence
Corresponds to table and not to row in relational environment In both Chen and Crow’s Foot models, entity is represented by rectangle containing entity’s name Entity name, a noun, is usually written in capital letters <already done?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

5 Attributes Characteristics of entities
Sometimes referred to as properties In Chen model, attributes are represented by ovals and are connected to entity rectangle with a line Each oval contains the name of attribute it represents In Crow’s Foot model, attributes are written in attribute box below entity rectangle <Say this material while using next slide as a handout (or draw)> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

6 Attributes (continued)
<DRAW> Key is underlined – this needs a key – add student id to drawing Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

7 Domains Attributes have domain Attributes may share a domain
Domain is attribute’s set of possible values Attributes may share a domain e.g. the domain for car_Year is integers (whole numbers) between 19?? and the current year E.g. domain for year in college is { Fr, So, Jr, Sr, Grad } <SKIP? > … how far back we need to allow may depend on what the system is doing – mechanic’s, DMV, car collector? Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

8 Primary Keys Underlined in the ERD
Key attributes are also underlined in frequently used table structure shorthand Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

9 Composite Primary Keys
Primary keys ideally composed of only single attribute Possible to use a composite key Primary key composed of more than one attribute <SKIP – already covered> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

10 Composite Primary Keys (continued)
<SKIP – already covered> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

11 The Entity Relationship (E-R) Model
Classes of Attributes A simple attribute cannot be subdivided. Examples: Age, Sex, and Marital status A composite attribute can be further subdivided to yield additional attributes. Examples: ADDRESS Street, City, State, Zip PHONE NUMBER  Area code, Exchange number NAME  last, first, Middle <do with figure on next slide> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

12 No longer a Figure The Attributes of the STUDENT Entity First Initial
Last Name Composite attribute – as opposed to a simple attribute <Draw> STUDENT STU ID No longer a Figure Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

13 The Entity Relationship (E-R) Model
Classes of Attributes A single-valued attribute can have only a single value. Examples: A person can have only one social security number. A manufactured part can have only one serial number. A student can only have one GPA Multivalued attributes can have many values. A person may have several college degrees. A household may have several phones with different numbers Cars can have multiple colors Multivalued attributes are shown by a double line connecting to the entity. <do with figure on next slide> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

14 Multivalued Attributes (continued)
<Handout > Single valued vs multi-valued (CAR _COLOR) Multi-valued attributes do not fit directly into a RDB design!!!! <see next slide> Another example – STUDENTs with more than one major Crow’s Foot format doesn’t have notation for multivalued attributes Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

15 The Entity Relationship (E-R) Model
Multivalued Attribute in Relational DBMS relational DBMS cannot implement multivalued attributes. Possible courses of action for the designer create several new attributes, one for each of the original multivalued attribute’s components (Figure 4.4). Create a new entity composed of the original multivalued attribute’s components (Figure 4.5). new attributes e.g. First Major, Second Major, Third Major? OR e.g. Car Color by sections as shown in Table 4.1 – a crappy solution in most situations New entity – the way to go even though it is a pain Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

16 Resolving Multivalued Attribute Problems (continued)
Usually a crappy solution <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

17 Resolving Multivalued Attribute Problems (continued)
<Handout> Usually the way to go – more flexible – easier to query (but a bit of a pain) – but can now have any number of colors on a car <Could do this for Students with 2 majors – and it would deal with the rare student with 3 majors> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

18 The Entity Relationship (E-R) Model
A derived attribute is not physically stored within the database; instead, it is derived (calculated) by using an algorithm. Example: AGE can be derived from the data of birth and the current date. Could be stored in DB if you understand the trade-off and decide it is worth it <Draw> Derived property – shown using a dashed line (I’ve frequently seen it as a dashed oval too) Crow’s Foot has no method for showing … faster retrieval vs more space AND risks of redundancy (need automatic updating to ensure not inconsistent) Figure A Derived Attribute Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

19 Derived Attributes (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

20 The Entity Relationship (E-R) Model
Relationships A relationship is an association between entities. Relationships are represented by diamond-shaped symbols. <already covered> Figure An Entity Relationship Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

21 The Entity Relationship (E-R) Model
Connectivity connectivity  one-to-one, one-to-many, and many-to-many. <trouble – many people use cardinality to mean this. Text book uses cardinality for something more specific (see next slide)> <SKIP – go directly to next slide which contrasts connectivity and cardinality> No Longer a figure in book: Connectivity in an ERD Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

22 The Entity Relationship (E-R) Model
Cardinality Cardinality expresses the specific number of entity occurrences associated with one occurrence of the related entity. <Handout ?> e.g. a professor can teach 0,1,2,or 3 sections (4 at La Salle). Section can be taught by 1 professor (min 1, max 1) e.g. a student can enroll in 1-6 classes (sections) , section can have 0-35 students enrolled (fewer at La Salle) A cardinality of (1,N) would indicate that there is no upper limit These limits come from organization’s business rules (not all business rules can be modeled in E/R diagram – e.g. student must have at least 2.0 GPA in order to graduate; student must owe $0 before registering; - some may need to be documented in English. BTW, many of these business rules have to be enforced by application code – also true of cardinality limits – DBMS won’t stop student from registering for 17 sections <George P. Burdell> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel No longer a Figure: Connectivity and Cardinality in an ERD

23 Connectivity and Cardinality (continued)
<shows Crow’s foot notation – Crow’s is much more primitive for this – one or many (no numbers) – and is more confusing – shown on opposite side as connectivities > Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

24 Existence Dependence Existence dependence Existence independence
Exist in database only when it is associated with another related entity occurrence Means FK cannot be null Existence independence Entity can exist apart from one or more related entities Sometimes refers to such an entity as strong or regular entity Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

25 Relationship Strength
Weak (non-identifying) relationships Exists if PK of related entity does not contain PK component of parent entity (related PK is only the FK) Strong (Identifying) Relationships Exists when PK of related entity contains PK component of parent entity Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

26 Weak (Non-Identifying) Relationships
(dotted line indicates (no corresponding notation in Chen)) Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

27 Weak (Non-Identifying) Relationships (continued)
(do not share PK) <Skip?> <Handout?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

28 Strong (Identifying) Relationships
(done differently – here share PK (part) ) <Skip?> <Handout?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

29 The Entity Relationship (E-R) Model
Weak Entities A weak entity is an entity that Is existence-dependent and Has a primary key that is partially or totally derived from the parent entity in the relationship. Hence the weak entity is the dependent entity involved in a strong (identifying) relationship The existence of a weak entity is indicated by a double rectangle. (in Chen notation) The weak entity inherits all or part of its primary key from its strong counterpart. I have a real problem with this definition – but this book is not the only one to use it. As the book notes, decision by database designer on primary key determines whether an entity is weak, or merely existence dependent. The Book’s own example of employee and dependent could EASILY be made not weak under this definition by using the dependent’s SSN as the dependent PK, and only using the employee number as a FK. If this is going to be the definition of weak, then the important thing at the conceptual data modeling stage has to be existence dependence instead of weak entity … see next slide Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

30 Weak Entities (continued)
(dependent is optional (in addition to being weak) – employee may or may not have dependents) <Handout? – just draw> <unfortunately, cardinalities are on opposite sides in the 2 notations> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

31 Weak Entities (continued)
<prob skip – unless helps draw the distinction> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

32 Relationship Participation
Optional participation One entity occurrence does not require corresponding entity occurrence in particular relationship Mandatory participation One entity occurrence requires corresponding entity occurrence in particular relationship Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

33 Relationship Participation (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

34 Relationship Participation (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

35 Relationship Participation (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

36 Relationship Participation (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

37 Relationship Degree Indicates number of entities or participants associated with a relationship Unary relationship Association is maintained within single entity Binary relationship Two entities are associated Ternary relationship Three entities are associated Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

38 Three Degrees of Relationships
<Handout – also, see next slide for more examples> Unary – prerequisite. The relationship is “recursive” Crow’s foot doesn’t allow M:N, so two 1:M relationships are drawn in course: course. Binary – most relationships Ternary ex – contribution going from a contributor to a specific fund and assigned to a specific recipient (not your usual donation situation – here you’re able to trace the recipient of the contributor’s money – which you couldn’t do if Contributor contributes to Fund & fund assigns to recipient were the relationships instead … ternary is not that common. Another Ternary example – SEAT – EVENT - CUSTOMER Can have higher degree … but hard to think of one Crows foot is implementation focused, so the CFR relationship is translated into a bridge entity Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

39 Relationship Degree (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

40 Relationship Degree (continued)
<Handout or show> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

41 Recursive Relationships
Relationship can exist between occurrences of the same entity set Naturally found within unary relationship < say with figure on next slide > Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

42 Recursive Relationships (continued)
<Handout?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

43 Recursive Relationships (continued)
<Create to Show? > a 1:1 relationship between employee and employee – represented all in one table Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

44 Recursive Relationships (continued)
<Create to Show?> <probably skip?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

45 Recursive Relationships (continued)
<if 1:M – skip> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

46 Recursive Relationships (continued)
<if M:N> <SKIP> COMPONENT is the bridge between PART and PART Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

47 Recursive Relationships (continued)
M:N relationship from course to course, like any M:N relationship, requires a table in the middle !!! <USE My Prereq table instead > Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

48 Composite Entities Also known as bridge entities
Composed of primary keys of each of the entities to be connected May also contain additional attributes that play no role in connective process <Covered by here???> … e.g.grade for ENROLL <Key new points?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

49 Composite Entities (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

50 Composite Entities (continued)
<will we have already covered this?> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

51 Composite Entities (continued)
<will we have already covered this?> <Handout?> Bridge entity will ALWAYS be M:1 with both entities it is bridging Bridge entity will be existence dependent on the other entities Bridge entity likely will be optional Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

52 Developing an ER Diagram
Database design is an iterative rather than a linear or sequential process begins with a general narrative (problem description) Iterative process E-R model is created and presented for review. process repeated until the end users and designers agree Book goes through this with their version of a university. (but don’t think it has to be that interactive. You can identify many of the appropriate entities with your initial analysis) Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

53 Developing an ER Diagram (continued)
Building an ERD usually involves the following activities: Create detailed narrative of organization’s description of operations Identify business rules based on description of operations Identify main entities and relationships from business rules Develop initial ERD Identify attributes and primary keys that adequately describe entities Revise and review ERD Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

54 Developing an ER Diagram (continued)
Tiny College Tiny College is divided into several schools Each school is composed of several departments Each department may offer courses Each department may have many professors assigned to it Each professor may teach up to four classes; each class is section of course Student may enroll in several classes, but (s)he takes each class only once during any given enrollment period <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

55 Developing an ER Diagram (continued)
Tiny College (continued) Each department has several students Each student has only a single major and is associated with a single department Each student has an advisor in his or her department Each advisor counsels several students The relationship between class is taught in a room and the room in the building <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

56 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

57 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

58 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

59 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

60 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

61 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

62 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

63 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

64 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

65 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

66 Developing an ER Diagram (continued)
<SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

67 Database Design Challenges: Conflicting Goals
Database design must conform to design standards – avoidance of redundancy / protection against inconsistency High processing speeds are often a top priority in database design – may lead to fewer tables than would be ideal design re: above Quest for timely information might be focus of database design Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

68 Database Design Challenges: Conflicting Goals (continued)
<SKIP> V1 – problems – update anomalies – if marriage or divorce happens, two updates needed or inconsistency results; semantics of marriage not necessarily enforced by DBMS – data could have employee 345 married to employee 346, but employee 346 married to employee 347 nulls are considered undesirable by some V2 – only really gets rid of nulls V3 – more elegant; less risk of inconsistency; but costs some in time for queries and maybe easy of writing queries (generally a low priority consideration) Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

69 Summary Entity relationship (ER) model
Uses ERD to represent conceptual database as viewed by end user ERM’s main components: Entities Relationships Attributes Includes connectivity and cardinality notations <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

70 Summary (continued) Connectivities and cardinalities are based on business rules In ERM, M:N relationship is valid at conceptual level ERDs may be based on many different ERMs Database designers are often forced to make design compromises <SKIP> Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel

71 End Chapter 4 Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel


Download ppt "Entity Relationship (ER) Modeling"

Similar presentations


Ads by Google