Data Modeling Using the Entity-Relationship

Slides:



Advertisements
Similar presentations
Database Design The process of finding user requirement
Advertisements

Conceptual Data Modeling: ER
Chapter 31 Chapter 3 Data Modeling Using the Entity-Relationship Model.
1 Entity-Relationship Model Gang Qian Department of Computer Science University of Central Oklahoma.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Week 3 Outline Overview of Database Design Process Example Database Application (COMPANY) ER Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Class Number – CS 304 Class Name - DBMS Instructor – Sanjay Madria Instructor – Sanjay Madria Lesson Title – ER Model.
CS 405G Introduction to Database Systems
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
Data Modeling Using the Entity-Relationship Model
Data Modeling Using the Entity-Relationship Model
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Data Modeling Using the Entity-Relationship (ER) Model CS 340: Introduction to Databases.
CSE314 Database Systems Data Modeling Using the Entity- Relationship (ER) Model Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model.
the Entity-Relationship Model
Lecture 2: Entity-Relationship Modeling
Dr. Mohamed Osman Hegaz1 Conceptual data base design: The conceptual models: The Entity Relationship Model.
Outline What is ER Model? And Why? Example COMPANY Database
Entity-Relationship Model. 2 Outline  What is ER Model? And Why?  Overview of Database Design Process  Example COMPANY Database  ER Model Concepts.
Entity-Relationship (ER) Data Model 概念資料模式 (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 4)
Data Modeling Using the Entity-Relationship (ER) Model
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Lecture On Database Analysis and Design By- Jesmin Akhter Lecturer, IIT, Jahangirnagar University.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
CS 405G: Introduction to Database Systems Lecture 2 : Database Design I.
Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Slide Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Conceptual Modeling and Database Design.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Entity-Relationship Model Chapter 3 II COSC 457 Sungchul Hong.
Data Modeling Using the Entity-Relationship (ER) Data Model (Based on Chapter 3 in Fundamentals of Database Systems by Elmasri and Navathe, Ed. 3)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Data Modelling Using Entity-Relationship (ER) Model
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 3- 1.
Lecture # 6.  A class of data models  Conveys semantic meaning  Implements databases more intelligently  Support more sophisticated user interfaces.
Database Systems – ER Diagrams EXAMPLE COMPANY DATABASE Requirements of the Company (oversimplified to illustrate) The company is organized into DEPARTMENTs.
Chapter 2 Data Modeling Using the Entity-Relationship (ER) Model Copyright © 2004 Pearson Education, Inc.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 3 Data Modeling Using Entity-Relationship Model.
Data Modeling Using the Entity-Relationship (ER) Data Model.
Data Modeling Using the Entity- Relationship (ER) Model.
Chapter 3: Data Modeling Using the Entity-Relationship (ER) Data Model
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Data Modeling Using the Entity- Relationship (ER) Model.
Copyright © 2016 Ramez Elmasr and Shamkant B. Navathei CHAPTER 3 Data Modeling Using the Entity-Relationship (ER) Model Slide 1- 1.
Data Modeling Using the Entity-Relationship (ER) Model
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model.
Example COMPANY Database
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 7 Lecture # 16 July 26,2012 Data Modeling using the Entity Relationship.
Data Modeling Using the Entity-Relationship (ER) Model
Data Modeling Using the Entity- Relationship (ER) Model
Comp 1100 Entity-Relationship (ER) Model
Data Modeling Using the Entity- Relationship (ER) Model
CS4222 Principles of Database System
Data Modeling Using the Entity- Relationship (ER) Model
Database Management Systems
ER model Ashima Wadhwa.
Entity Relationship Model
College of Arts & Science Computer Science Department
Data Modeling Using the Entity- Relationship Model
Initial Design of Entity Types: EMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT Gender.
Presentation transcript:

Data Modeling Using the Entity-Relationship Chapter 3 Data Modeling Using the Entity-Relationship (ER) Model 3.1 Using High-Level Conceptual Data Models for Database Design 3.2 An Example Database Application 3.3 Entity types, Entity Sets, Attributes, and Keys 3.4 Relationships, Relationship Types, Roles, and Structural Constraints 3.5 Weak Entity Types 3.6 Refining the ER Design for the COMPANY Database 3.7 ER Diagrams, Naming conventions, and Design Issues 3.8 Summary 3-1

Figure 3.1 Phases of Database Design (Simplified) User-defined operations (transactions) Data flow diagrams Data types Relationships constraints 3-2

3.2 An Example Database Application: COMPANY Requirements for the COMPANY Database: The company is organized into DEPARTMENTs. Each department has a unique name, a unique number, and an employee who manages the department. We keep track of the start date of the department manager. A department may have several locations. Each department controls a number of PROJECTs. Each project has a unique name, a unique number and is located at a single location. We store each EMPLOYEE’s name, social security number, address, salary, sex, and birth date. 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. Each employee may have a number of DEPENDENTs. For each dependent, we keep their name, sex, birth date, and relationship to the employee. 3-3

Figure 3.2 ER schema diagram for COMPANY database 3-4

3.3 Entity types, Entity Sets, Attributes, and Keys entity data relationship attribute ER Model Concepts 3.3.1 Entities and Attributes Entities are specific objects or things in the mini-world that are represented in the database; for example, the EMPLOYEE John Smith, the Research DEPARTMENT, the ProductX PROJECT. Attributes are properties used to describe an entity; for example, an EMPLOYEE entity may have a Name, SSN, Address, Sex, BirthDate. A specific entity will have a value for each of its attributes; for example a specific employee entity may have Name=‘John Smith’, SSN=‘123456789’, Address=‘731 Fondren, Houston, TX’, Sex=‘M’, BirthDate=’09-JAN-55’. Independent existence 3-5

Figure 3.3 Two entities and their attribute values employee department 3-6

• Single-valued: single value for that entity (e.g., age) Types of Attributes: • Simple (Atomic): Each entity has a single atomic value for the attribute; for example SSN or Sex. (不可分) • Composite: The attribute may be composed of several components; for example Address(Apt#, House#, Street, City, State, ZipCode, County) or Name (FirstName, MiddleName, LastName) . Composition may form a hierarchy where some components are themselves composite. (see 3-9) (1) • Single-valued: single value for that entity (e.g., age) • Multi-valued: An entity may have multiple values for that attribute; for example Color of a CAR or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}. (may have lower and upper bounds) (2) 3-6a

-In general, composite and multi-valued attributes may be nested arbitrarily to any number of levels although this is rare. For example, PreviousDegrees of a STUDENT is a composite multi-valued attribute denoted by {PreviousDegrees (College, Year, Degree, Field)}. multi-valued composite • stored • derived Age (derived attribute) is derivable from BirthDate (stored attribute), I.e., Current Date-BirthDate (3) 3-6a

 not applicable, e.g., Apartment Number, College Degree (4) Null Values  not applicable, e.g., Apartment Number, College Degree  unknown - the attribute value exists but is missing e.g., Height - it is not known whether the value exists e.g., HomePhone

Figure 3.4 A hierarchy of composite attributes Houston Texas 77001 2311 Kirby Null User sometimes refers to composite attribute, but at other times refers to its components. 3-6b

3.3.2 Entity Types, Entity Sets, Keys, and Value Sets Entities with the same basic attributes are grouped or typed into an entity type. For example, the EMPLOYEE entity type or the PROJECT entity type (see 3-12) entity type (intension) entity set (extension) An attribute of an entity type for which each entity must have a unique value is called a Key attribute of the entity type. For example SSN of EMPLOYEE. key (uniqueness) constraint A key attribute may be composite. For example, VehicleRegistrationNumber is a key of the CAR entity type with components (Number, State). An entity type may have more than one key. For example, the CAR entity type may have two keys: VehicleIdentificationNumber and VehicleRegistraionNumber(Number, State). (see 3-13) 3-6c

Figure 3.6 Two entity types and some of the member entities of each 3-8

key attribute Figure 3.7 CAR entity type Component of composite attribute multivalued attribute Registration attribute VehicleID attribute key attribute Uniqueness property must hold for every extension of the entity set 3-9

Minit Lname Fname Number Name Name Sex SSN Address Salary Bdate Locations Sex NumberOf Employee SSN Address Department Salary Bdate EMPLOYEE singled multiple-valued Entity type key attribute derived attribute 3-7

Value Sets (Domains) of Attributes Each simple attribute of an entity type is associated with a value set (or domain of values). e.g. Age:16-70, Name: char string, …  An attribute A of entity type E whose value set is V: e.g. V={1,2} A: E  P(V) power set P(V)={,{1},{2},{1,2}}   null empty set   singled-valued attribute singleton   multivalued attribute no restriction For a composite attribute A, the value set V is Value sets are not displayed in ER diagram. 3-10

( ): composite attribute { }: multivalued attribute Figure 3.5 A complex attribute AddressPhone with multivalued and composite component. {AddressPhone({Phone(AreaCode, PhoneNumber)}, Address(StreetAddress(Number, Street, ApartmentNumber), City, State, Zip))} ( ): composite attribute { }: multivalued attribute An employee may have more than one AddressPhone, i.e., office and home. 3-11

3.3.3 Initial Conceptual Design of the COMPANY Database Specification (refer to 3-3) Refer to Fig. 3.2 (3-4) key attribute key attribute Figure 3.8 { …. } : multivalued attribute ( ) : component of a composite attribute 3-12

3.4.1 Relationship Types, Sets and Instances 3.4 Relationships, Relationship Types, Roles, and Structural Constrains DEPARTMENT 3.4.1 Relationship Types, Sets and Instances - A relationship relates two or more distinct entities with a specific meaning; for example, EMPLOYEE John Smith work on the ProductX PROJECT or EMPLOYEE Franklin Wong work for the Research DEPARTMENT. (see 3-19) - Relationships of the same type are grouped or typed into a relationship type. For example, the WORKS_ON relationship type in which EMPLOYEEs and PROJECTs participate, or the MANAGES relationship type in which EMPLOYEEs and DEPARTMENTs participate. MANAGES EMPLOYEE WORKS_ON relationship type PROJECT relationship instance 3-13

Figure 3.9 Some instances of the WORKS_FOR relationship many-to-one 3-14

3.4.2 Relationship Degree, Role Names, and Recursive Relationships DEPARTMENT -The degree of a relationship type is the number of participation entity types. Both MANAGES and WORKS_ON are binary relationships. ternary relationship: degree 3 (see 3-21) -More than one relationship type can exist with the same participation entity types; for example, MANAGES and WORKS_FOR are distinct relationships between EMPLYEE and DEPARTMENT participate. -Relationship as Attributes WORKS_FOR relationship DEPARTMENT OF EMPLOYEE (see 3-17) EMPLOYEES OF DEPARTMENT : multivalued WORKS_FOR MANAGES EMPLOYEE 3-13

Figure 3.10 The ternary relationship SUPPLY s supplies part p to project j 3-15

-Role Names and Recursive Relationships. - A relationship can relate two entities of the same entity type; for example, a SUTERVISION relationship type relates one EMPLOYEE (in the role of supervisee ) to another EMPLOYEE (in the role of supervisor). This is called a recursive relationship type. (see 3-23) For example: in the WORKS_FOR relationship type EMPLOYEE WORKS_FOR DEPARTMENT role: employee / worker department / employer 3-13

3-17

3.4.3 Constrains on Relationship Types - Cardinality ratio ( of a binary relationship): 1:1, 1:N, N:1, or M:N MANAGES (1:1, see 3-25) WORKS_FOR (1:N, see 3-19) WORKS_ON ( M:N, see 3-26) - Participation constraint(on each participation entity type): total (called existence dependency) or partial. Every employee must work for a department. EMPLOYEE in WORKS_FOR : total total participation (完全參與) : double line partial participation (部分參與) : single line structural constraints 3-16

Figure 3.12 MANAGES one-to-one 1:1 relationship Partial participation of EMPLOYEE Total participation of DEPARTMENT 3-18

Figure 3.13 WORK_ON M:N relationship 3-19

3.3.4 Attributes of Relationship Types - A relationship type can have attributes; for example, HoursPerWeek of WORKS_ON; its value for each relationship instance describes the number of hours per week that an EMPLOYEE works on a PROJECT. EMPLOYEE WORKS_ON PROJECT HOUR 3-20

- Attributes of 1:1 or 1:N relationship types can be migrated to one of the participating entity types. StartDate 1 1 MANAGES EMPLOYEE DEPARTMENT - For M:N relationship types, some attributes may be determined by the combination of participating entities. must be specified as relationship attributes. HOURS N M WORKS_ON EMPLOYEE PROJECT 3-20

- For a 1:1 relationship type, a relationship attribute can be migrated to either participating entity types. - For a 1:N relationship type, a relationship attribute can be migrated only to the entity type at the N side. StartDate 1 N WORKS_FOR EMPLOYEE DEPARTMENT 3-20

3.5 Weak Entity Types (vs. Strong Entity types) - An entity type that does not have a key attribute - A weak entity type must participate in an identifying relationship type with an owner or identifying entity type. - Entities are identified by the combination of :  A partial key of the weak entity type set of attributes can uniquely identify weak entities that are related to the same owner entity  The particular entity they are related to in the identifying entity type 3-21

A weak entity type always has a total participation constraint Example: Suppose that a DEPENDENT entity is identified by the dependent’s first name and birthdate, and the specific EMPLOYEE that the dependent is related to. DEPENDENT is a weak entity type with EMPLOYEE as its identifying entity type via the identifying relationship type DEPENDENT_OF. A weak entity type always has a total participation constraint with respect to its identifying relationship. (existence dependency) 3-21

3.6 Refine the ER Design for COMPANY Database 3-22 1.MANAGES, a 1:1 relationship type between EMPLOYEE and DEPARTMENT. EMPLOYEE participation is partial. DEPARTMENT participation is not clear from the requirements. We question the users, who say that a department must have a manager at all times,which implies total participation.The attribute StartDate is assigned to this relationship type. 2.WORKS_FOR, a 1:N relationship type between DEPARTMENT and EMPLOYEE. Both participations are total. 3.CONTROLS, a 1:N relationship type between DEPARTMENT and PROJECT. The participation of PROJECT is total,whereas that of DEPARTMENT is determined to be partial, after consultation with the users. 3-22

4.SUPERVISION, a 1:N relationship type between EMPLOYEE ( in the supervisor role) and EMPLOYEE (in the supervisee role). Both participations are determined to be partial, after the users indicate that not every employee is a supervisor and not every employee has a supervisor. 5.WORKS_ON,determined to be an M:N relationship type with attribute Hours, after the users indicate that a project can have several employees working on it. Both participations are determined to be total. 6.DEPENDENTS_OF, a 1:N relationship type between EMPLOYEE and DEPENDENT, which is also the identifying relationship for the weak entity type DEPENDENT,which is also the identifying relationship for the weak entity type DEPENDENT. The participation of EMPLOYEE is partial, whereas that of DEPENDENT is total. 3-22

Figure 3.14 Summary of ER diagram notation for each entity e in E, e must participate in at least min and at most max relationship instances in R at all times. 3-23

- Must have - Derived from the mini-world constraints. Alternative (min, max) notation for relationship structural constraints: Specified on each participation of an entity type E in a relationship type R. - Specifies that each entity e in E participates in at least min and at most max relationship instances in R. - Default (no constraint): min=0, max=n. - Must have - Derived from the mini-world constraints. Examples: (a) A department has exactly one manager and an employee can manage at most one department. - Specify (0,1) for participation of EMPLOYEE in MANAGES - Specify (1,1) for participation of DEPARTMENT in MANAGES (b) An employee can work for exactly one department but a department can have any number of employees. - Specify (1,1) for participation of EMPLOYEE in WORKS_FOR - Specify (0,n) for participation of DEPARTMENT in WORKS_FOR min=0 partial participation min>0 total participation 3-23a

Figure 3.14 ER diagram for the COMPANY Scheme Proper Naming of Schema Constructs 3-23b

3.7.2 Proper Naming of Schema Constructs entity types attributes relationship types roles nouns names for verbs 3.7.3 Design Choices for ER Conceptual Design A concept may be first modeled as an attribute and then refined into a relationship. An attribute that exists in several entity types may be refined into its own independent entity type. 3-24