56
Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1

Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 1

Page 2: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Chapter 3p

Data Modeling Using the Entity-Relationship (ER) ModelRelationship (ER) Model

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe

Page 3: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Ch t O tliChapter OutlineO i f D t b D i POverview of Database Design ProcessExample Database Application (COMPANY)ER Model ConceptsER Model Concepts

Entities and AttributesEntity Types, Value Sets, and Key AttributesEntity Types, Value Sets, and Key AttributesRelationships and Relationship TypesWeak Entity TypesRoles and Attributes in Relationship Types

ER Diagrams - NotationER Di f COMPANY S hER Diagram for COMPANY SchemaAlternative Notations – UML class diagrams, others

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 3

Page 4: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Overview of Database Design Process

Two main activities:Database designApplications design

Focus in this chapter on database designFocus in this chapter on database designTo design the conceptual schema for a database applicationapplication

Applications design focuses on the programs and interfaces that access the databaseinterfaces that access the database

Generally considered part of software engineering

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 4

Page 5: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Overview of Database Design Process

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 5

Page 6: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E l COMPANY D t bExample COMPANY Database

W d t t d t b h d iWe need to create a database schema design based on the following (simplified) requirementsof the COMPANY Database:of the COMPANY Database:

The company is organized into DEPARTMENTs. Each department has a name number and anEach department has a name, number and an employee who manages the department. We keep track of the start date of the department manager. p gA department may have several locations.Each department controls a number of PROJECT E h j h iPROJECTs. Each project has a unique name, unique number and is located at a single location.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 6

Page 7: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Example COMPANY Database (C td )(Contd.)

W t h EMPLOYEE’ i l itWe store each EMPLOYEE’s social security number, address, salary, sex, and birthdate.

Each employee works for one department but mayEach employee works for one department but may work on several projects.We keep track of the number of hours per week that p pan employee currently works on each project.We also keep track of the direct supervisor of each

lemployee.Each employee may have a number of DEPENDENTsDEPENDENTs.

For each dependent, we keep track of their name, sex, birthdate, and relationship to the employee.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 7

sex, birthdate, and relationship to the employee.

Page 8: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

ER M d l C tER Model ConceptsEntities and AttributesEntities 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 the attributes Name, SSN, Address, Sex, BirthDate

A specific entity will have a value for each of its attributes.p yFor example a specific employee entity may have Name='John Smith', SSN='123456789', Address ='731, Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55‘

Each attribute has a value set (or data type) associated with it – e.g. integer, string, subrange, enumerated type, …

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 8

Page 9: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

T f Att ib t (1)Types of Attributes (1)SimpleSimple

Each entity has a single atomic value for the attribute. For example, SSN or Sex.

CompositeThe attribute may be composed of several components. For example:p

Address(Apt#, House#, Street, City, State, ZipCode, Country), orName(FirstName, MiddleName, LastName).Composition may form a hierarchy where some components p y y pare themselves composite.

Multi-valuedAn entity may have multiple values for that attribute ForAn entity may have multiple values for that attribute. For example, Color of a CAR or PreviousDegrees of a STUDENT.

Denoted as {Color} or {PreviousDegrees}.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 9

Page 10: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

T f Att ib t (2)Types of Attributes (2)

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)}Multiple PreviousDegrees values can existEach has four subcomponent attributes:

College, Year, Degree, Field

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 10

Page 11: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E l f it tt ib tExample of a composite attribute

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 11

Page 12: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E tit T d K Att ib t (1)Entity Types and Key Attributes (1)

Entities with the same basic attributes are grouped or typed into an entity type. g p yp y yp

For example, the entity type EMPLOYEE and PROJECTand PROJECT.

An attribute of an entity type for which each entity must have a unique value is called a key attribute of the entity type. y y yp

For example, SSN of EMPLOYEE.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 12

Page 13: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E tit T d K Att ib t (2)Entity Types and Key Attributes (2)

A key attribute may be composite. VehicleTagNumber is a key of the CAR entity g y ytype with components (Number, State).

An entity type may have more than one key.An entity type may have more than one key. The CAR entity type may have two keys:

VehicleIdentificationNumber (popularly called VIN)VehicleIdentificationNumber (popularly called VIN)VehicleTagNumber (Number, State), aka license plate numberplate number.

Each key is underlined

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 13

Page 14: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Di l i E tit tDisplaying an Entity type

I ER di tit t i di l d iIn ER diagrams, an entity type is displayed in a rectangular boxAtt ib t di l d i lAttributes are displayed in ovals

Each attribute is connected to its entity typeComponents of a composite attribute are connected to the oval representing the composite attributeattributeEach key attribute is underlinedMultivalued attributes displayed in double ovalsMultivalued attributes displayed in double ovals

See CAR example on next slide

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 14

Page 15: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Entity Type CAR with two keys and a corresponding Entity Set

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 15

Page 16: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E tit S tEntity Set

Each entity type will have a collection of entities stored in the database

Called the entity setPrevious slide shows three CAR entity instances yin the entity set for CARSame name (CAR) used to refer to both the entitySame name (CAR) used to refer to both the entity type and the entity setEntity set is the current state of the entities of thatEntity set is the current state of the entities of that type that are stored in the database (extension)E tit T d ib th h i t i

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 16

Entity Type describe the schema or intension.

Page 17: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Initial Design of Entity Types for the D t b S hCOMPANY Database Schema

Based on the requirements, we can identify four initial entity types in the COMPANY database:

DEPARTMENTPROJECTEMPLOYEEDEPENDENTDEPENDENT

Their initial design is shown on the following slideTh i iti l tt ib t h d i d f thThe initial attributes shown are derived from the requirements description

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 17

Page 18: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Initial Design of Entity Types:g y ypEMPLOYEE, DEPARTMENT, PROJECT, DEPENDENT

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 18

Page 19: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Refining the initial design by introducing relationships

The initial design is typically not completeSome aspects in the requirements will be p qrepresented as relationshipsER model has three main concepts:ER model has three main concepts:

Entities (and their entity types and entity sets)Attributes (simple composite multivalued)Attributes (simple, composite, multivalued)Relationships (and their relationship types and relationship sets)relationship sets)

We introduce relationship concepts next

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 19

Page 20: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Relationships and Relationship Types (1)

A relationship relates two or more distinct entities with aA relationship relates two or more distinct entities with a specific meaning.

For example, EMPLOYEE John Smith works on the ProductX PROJECT EMPLOYEE F kli W thPROJECT, or EMPLOYEE Franklin Wong manages the Research DEPARTMENT.

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 p prelationship type in which EMPLOYEEs and DEPARTMENTs participate.

The degree of a relationship type is the number of g p ypparticipating entity types.

Both MANAGES and WORKS_ON are binary relationships.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 20

Page 21: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Relationship instances of the WORKS_FOR N:1 relationship between EMPLOYEE and DEPARTMENTrelationship between EMPLOYEE and DEPARTMENT

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 21

Page 22: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Relationship instances of the M:N WORKS_ON l ti hi b t EMPLOYEE d PROJECTrelationship between EMPLOYEE and PROJECT

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 22

Page 23: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Relationship type vs. relationship set (1)

Relationship Type:Is the schema description of a relationshipIdentifies the relationship name and the participating entity typesAlso identifies certain relationship constraints

Relationship Set:Relationship Set:The current set of relationship instances represented in the databaserepresented in the databaseThe current state of a relationship type

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 23

Page 24: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Relationship type vs. relationship set (2)

Previous figures displayed the relationship setsEach instance in the set relates individual participating entities – one from each participating entity typey yIn ER diagrams, we represent the relationship type as follows:type as follows:

Diamond-shaped box is used to display a relationship typerelationship typeConnected to the participating entity types via straight lines

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 24

straight lines

Page 25: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Refining the COMPANY database schema by introducing relationships

By examining the requirements, six relationship types are identifiedAll bi l ti hi ( d 2)All are binary relationships( degree 2)Listed below with their participating entity types:

WORKS FOR (b t EMPLOYEE DEPARTMENT)WORKS_FOR (between EMPLOYEE, DEPARTMENT)MANAGES (also between EMPLOYEE, DEPARTMENT)CONTROLS (between DEPARTMENT PROJECT)CONTROLS (between DEPARTMENT, PROJECT)WORKS_ON (between EMPLOYEE, PROJECT)SUPERVISION (between EMPLOYEE (as subordinate)SUPERVISION (between EMPLOYEE (as subordinate), EMPLOYEE (as supervisor))DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 25

Page 26: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

ER DIAGRAM – Relationship Types are:WORKS FOR MANAGES WORKS ON CONTROLS SUPERVISION DEPENDENTS OFWORKS_FOR, MANAGES, WORKS_ON, CONTROLS, SUPERVISION, DEPENDENTS_OF

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 26

Page 27: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Di i R l ti hi TDiscussion on Relationship Types

In the refined design, some attributes from the initial entity types are refined into relationships:

Manager of DEPARTMENT > MANAGESManager of DEPARTMENT -> MANAGESWorks_on of EMPLOYEE -> WORKS_ONDepartment of EMPLOYEE > WORKS FORDepartment of EMPLOYEE -> WORKS_FORetc

In general more than one relationship type can existIn general, more than one relationship type can exist between the same participating entity types

MANAGES and WORKS FOR are distinct relationship _ ptypes between EMPLOYEE and DEPARTMENTDifferent meanings and different relationship instances.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 27

Page 28: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

R i R l ti hi TRecursive Relationship Type

An relationship type whose with the same participating entity type in distinct rolesE l th SUPERVISION l ti hiExample: the SUPERVISION relationshipEMPLOYEE participates twice in two distinct roles:

i ( b ) lsupervisor (or boss) rolesupervisee (or subordinate) role

Each relationship instance relates two distinctEach relationship instance relates two distinct EMPLOYEE entities:

One employee in supervisor roleOne employee in supervisor roleOne employee in supervisee role

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 28

Page 29: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

W k E tit TWeak Entity TypesA tit th t d t h k tt ib tAn entity that does not have a key attributeA weak entity must participate in an identifying relationship type with an owner or identifying entity typeEntities are identified by the combination of:

A partial key of the weak entity typeThe particular entity they are related to in the identifying entityThe particular entity they are related to in the identifying entity type

Example: A DEPENDENT tit i id tifi d b th d d t’ fi tA DEPENDENT entity is identified by the dependent’s first name, and the specific EMPLOYEE with whom the dependent is relatedName of DEPENDENT is the partial keyDEPENDENT is a weak entity typeEMPLOYEE is its identifying entity type via the identifying relationship type DEPENDENT OF

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 29

p yp _

Page 30: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

C t i t R l ti hiConstraints on Relationships

Constraints on Relationship Types(Also known as ratio constraints)C di lit R ti ( ifi i ti i ti )Cardinality Ratio (specifies maximum participation)

One-to-one (1:1)One-to-many (1:N) or Many-to-one (N:1)One-to-many (1:N) or Many-to-one (N:1)Many-to-many (M:N)

Existence Dependency Constraint (specifies minimump y ( pparticipation) (also called participation constraint)

zero (optional participation, not existence-dependent)( d i i i i d d )one or more (mandatory participation, existence-dependent)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 30

Page 31: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Many-to-one (N:1) Relationship

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 31

Page 32: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Many to many (M:N) RelationshipMany-to-many (M:N) Relationship

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 32

Page 33: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Displaying a recursive l ti hirelationshipI i l ti hi tIn a recursive relationship type.

Both participations are same entity type in different rolesdifferent roles.For example, SUPERVISION relationships between EMPLOYEE (in role of supervisor orbetween EMPLOYEE (in role of supervisor or boss) and (another) EMPLOYEE (in role of subordinate or worker).

In following figure, first role participation labeled with 1 and second role participation labeled with 22.In ER diagram, need to display role names to distinguish participations.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 33

distinguish participations.

Page 34: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

A Recursive Relationship Supervision`p p

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 34

Page 35: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Recursive Relationship Type is: SUPERVISION(participation role names are shown)(participation role names are shown)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 35

Page 36: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Att ib t f R l ti hi tAttributes of Relationship types

A l ti hi t h tt ib tA relationship type can have attributes:For example, HoursPerWeek of WORKS_ONIts value for each relationship instance describes the number of hours per week that an EMPLOYEE works on a PROJECTworks on a PROJECT.

A value of HoursPerWeek depends on a particular (employee, project) combination( p y , p j )

Most relationship attributes are used with M:N relationships

In 1:N relationships, they can be transferred to the entity type on the N-side of the relationship

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 36

Page 37: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Example Attribute of a Relationship Type: H f WORKS ONHours of WORKS_ON

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 37

Page 38: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Notation for Constraints on R l ti hiRelationships

C di lit ti ( f bi l ti hi ) 1 1Cardinality ratio (of a binary relationship): 1:1, 1:N, N:1, or M:N

Sh b l i i t b thShown by placing appropriate numbers on the relationship edges.

Participation constraint (on each participatingParticipation constraint (on each participating entity type): total (called existence dependency) or partialor partial.

Total shown by double line, partial by single line.NOTE: These are easy to specify for BinaryNOTE: These are easy to specify for Binary Relationship Types.

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 38

Page 39: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Alternative (min, max) notation for l ti hi t t l t i trelationship structural constraints:Specified on each participation of an entity type E in a relationshipSpecified on each participation of an entity type E in a relationship type RSpecifies that each entity e in E participates in at least min and at most max relationship instances in Rmost max relationship instances in RDefault(no constraint): min=0, max=n (signifying no limit)Must have min≤max, min≥0, max ≥1A minimum value of 1 indicates total participation of theA minimum value of 1 indicates total participation of theentity set in the relationship set.Examples:

A department has exactly one manager and an employee can manage at most one departmentmanage at most one department.

Specify (0,1) for participation of EMPLOYEE in MANAGESSpecify (1,1) for participation of DEPARTMENT in MANAGES

An employee can work for exactly one department but aAn 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_FORSpecify (1 n) for participation of DEPARTMENT in WORKS FOR

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 39

Specify (1,n) for participation of DEPARTMENT in WORKS_FOR

Page 40: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

The (min,max) notation for l ti hi t i trelationship constraints

Read the min,max numbers next to the entity type and looking away from the entity type

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 40

type and looking away from the entity type

Page 41: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

COMPANY ER Schema Diagram using (min, max) notationmax) notation

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 41

Page 42: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Alt ti di ti t tiAlternative diagrammatic notation

ER diagrams is one popular example for displaying database schemasMany other notations exist in the literature and in various database design and modeling toolsg gAppendix A illustrates some of the alternative notations that have been usednotations that have been usedUML class diagrams is representative of another way of displaying ER concepts that is used inway of displaying ER concepts that is used in several commercial design tools

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 42

Page 43: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Summary of notation for ER diagrams

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 43

Page 44: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

UML class diagrams

Represent classes (similar to entity types) as largeRepresent classes (similar to entity types) as large rounded boxes with three sections:

Top section includes entity type (class) nameSecond section includes attributesThird section includes class operations (operations are not in basic ER model)in basic ER model)

Relationships (called associations) represented as lines connecting the classes

Oth UML t i l l diff f ER t i lOther UML terminology also differs from ER terminologyUsed in database design and object-oriented software designgUML has many other types of diagrams for software design (see Chapter 12)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 44

Page 45: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

UML class diagram for COMPANY database schema

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 45

Page 46: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Other alternative diagrammatic notations

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 46

Page 47: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

R l ti hi f Hi h DRelationships of Higher Degree

Relationship types of degree 2 are called binaryRelationship types of degree 3 are called ternary p yp g yand of degree n are called n-aryIn general, an n-ary relationship is notIn general, an n ary relationship is not equivalent to n binary relationshipsConstraints are harder to specify for higher-Constraints are harder to specify for higher-degree relationships (n > 2) than for binary relationshipsrelationships

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 47

Page 48: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Discussion of n-ary relationships (n > 2)

In general, 3 binary relationships can represent different information than a single ternary relationship (see Figure 3 17a and b on next slide)Figure 3.17a and b on next slide)If needed, the binary and n-ary relationships can all be included in the schema design (see Figure 3 17a and bincluded in the schema design (see Figure 3.17a and b, where all relationships convey different meanings)In some cases, a ternary relationship can be so e cases, a e a y e a o s p ca berepresented as a weak entity if the data model allows a weak entity type to have multiple identifying relationships (and hence multiple owner entity types) (see Figure 3.17c)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 48

Page 49: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

E l f t l ti hiExample of a ternary relationship

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 49

Page 50: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Discussion of n-ary relationships (n > 2)

If a particular binary relationship can be derived from a higher-degree relationship at all times, then it is redundantFor example, the TAUGHT_DURING binary yrelationship in Figure 3.18 (see next slide) can be derived from the ternary relationship OFFERS (based on the meaning of the relationships)

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 50

Page 51: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Another example of a ternary relationship

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 51

Page 52: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Displaying constraints on higher-degree relationships

The (min, max) constraints can be displayed on the edges – however, they do not fully describe the constraintsDi l i 1 M N i di t dditi l t i tDisplaying a 1, M, or N indicates additional constraints

An M or N indicates no constraintA 1 indicates that an entity can participate in at most oneA 1 indicates that an entity can participate in at most one relationship instance that has a particular combination of the other participating entitiesg

In general, both (min, max) and 1, M, or N are needed to describe fully the constraints

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 52

Page 53: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

D t M d li T lData Modeling ToolsA b f l t l th t t l d liA number of popular tools that cover conceptual modeling and mapping into relational schema design.

Examples: ERWin S- Designer (Enterprise ApplicationExamples: ERWin, S Designer (Enterprise Application Suite), ER- Studio, etc.

POSITIVES: Serves as documentation of application requirements, easy user interface - mostly graphics editor support

NEGATIVES:NEGATIVES:Most tools lack a proper distinct notation for relationships with relationship attributesMostly represent a relational design in a diagrammatic form rather than a conceptual ER-based design

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 53

Page 54: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Some of the Currently Available Automated Database Design ToolsAutomated Database Design Tools

COMPANY TOOL FUNCTIONALITYEmbarcadero Technologies

ER Studio Database Modeling in ER and IDEF1X

DB Artisan Database administration, space and security managementmanagement

Oracle Developer 2000/Designer 2000 Database modeling, application developmentPopkin S ft

System Architect 2001 Data modeling, object modeling, process modeling, t t d l i /d iSoftware structured analysis/design

Platinum (Computer Associates)

Enterprise Modeling Suite: Erwin, BPWin, Paradigm Plus

Data, process, and business component modeling

Associates) Persistence Inc.

Pwertier Mapping from O-O to relational model

Rational (IBM) Rational Rose UML Modeling & application generation in C++/JAVA

Resolution Ltd. Xcase Conceptual modeling up to code maintenance

Sybase Enterprise Application Suite Data modeling business logic modeling

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 54

Sybase Enterprise Application Suite Data modeling, business logic modelingVisio Visio Enterprise Data modeling, design/reengineering Visual Basic/C++

Page 55: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Extended Entity-Relationship (EER) M d l (i t h t )Model (in next chapter)

The entity relationship model in its original form y p gdid not support the specialization and generalization abstractionsgNext chapter illustrates how the ER model can be extended withextended with

Type-subtype and set-subset relationshipsSpecialization/Generalization HierarchiesSpecialization/Generalization HierarchiesNotation to display them in EER diagrams

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 55

Page 56: Slide 3- 1site.iugaza.edu.ps/wp-content/uploads/DB_Ch03.pdf · 2013. 12. 9. · Title: Microsoft PowerPoint - DB Ch03 [Compatibility Mode] Author: hzaq Created Date: 10/24/2009 2:21:22

Ch t SChapter Summary

ER Model Concepts: Entities, attributes, relationshipsConstraints in the ER modelUsing ER in step-by-step conceptual schemaUsing ER in step by step conceptual schema design for the COMPANY databaseER Diagrams - NotationER Diagrams - NotationAlternative Notations – UML class diagrams, othersothers

Copyright © 2007 Ramez Elmasr and Shamkant B. Navathei Slide 3- 56