Top Banner
Conceptual Modelling using ERD (with focus on Chen Notation) Lesson 3
49
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 3a (1).ppt

Conceptual Modelling using ERD(with focus on Chen Notation)

Lesson 3

Page 2: Lecture 3a (1).ppt

2

Lesson Outcomes

At the end of the lesson, students should be able to :• Conceptually depict a database structure in an ER Diagram

(using Chen Notation)• Identify and describe the main characteristics of ERD’s

components such as – Entity– Attributes

• Identifier attributes (Keys) – Primary/Composite/Foreign

• Composite and simple attributes

• Single-valued and Multivalued attributes

– Relationships• Connectivity & cardinality

• Degree of relationship

Page 3: Lecture 3a (1).ppt

PRODUCT CUSTOMER

SUPPLIER

purchasedBy

suppliedBy

m n

1

m

prodID

name

price qtyBoughtcustID

name

contactNo

suppID

name address

contactNo

Page 4: Lecture 3a (1).ppt

4

Intro to Modeling

• In the programming env., a problem that needs to be solved must be critically analyze first before a solution can be designed.

• In programming, the analysis will identify (1) the inputs (2) the outputs (3) the process

• After that an approach to solve the problem will be selected, e.g., procedural/structured, object-oriented, logical etc.

• Then, if for example, structured approach is selected, then the solution will be designed using certain model, e.g., flowchart, pseudocode, etc.

Page 5: Lecture 3a (1).ppt

5

Intro to Modeling – cont’d

• After that only the actual coding will be done using certain programming language, e.g., C.

• The C compiler itself can be provided by many publishers such as Turbo C, Borland C, etc.

Page 6: Lecture 3a (1).ppt

6

Intro to Entity Relationship (ER) Model• The same concept applies in database development

• In the database env., a problem that needs to be solved must be critically analyze first before a solution can be designed. (Here the problem is to keep storage of data for later use)

• The analysis will identify (1) the structure of the storage (2) the transactions/operations to be done

• Then, the solution will be depicted using certain model, e.g., ER, UML – For structure : ER Diagram, UML Class Diagram, etc.– For transaction: relational algebra, etc.

Page 7: Lecture 3a (1).ppt

7

Entity Relationship (ER) Model – cont’d

• After that a solution will be refined using certain approach, e.g., relational, object-oriented, network, hierarchical, etc.

• After that only the actual coding will be done using database language called Structured Query Language (SQL).

• Again SQL is supported by many database software, e.g., Oracle, MySQL, Informix, SQL Server, etc.

Page 8: Lecture 3a (1).ppt

8

Entity Relationship (ER) Model – cont’d

Database Structure Modeling using ERD

• ERD is a pictorial representation of a database structure. Different shapes of items in the diagram represents different components of the database. – Entities– Attributes– Relationships

• There are many variations in terms of the shapes. The popular ones are based on Chen and Crow foot notations.

Page 9: Lecture 3a (1).ppt

One-to-One One-to-Many Many-to-Many

CUSTOMER ACCOUNT STUDENT COURSE

1 1 1 M M N

STUDENT

STUDENT

STUDENT

STUDENT

1

2

3

4

5

COURSE

COURSE

COURSE

COURSE

CUSTOMER

CUSTOMER

CUSTOMER

CUSTOMER

ACCOUNT

ACCOUNT

ACCOUNT

ACCOUNT

EMPLOYEE

EMPLOYEE

EMPLOYEE

EMPLOYEE

EMPLOYEE

TEMP_EMP

TEMP_EMP

TEMP_EMP

TEMP_EMP

TEMP_EMP

Variation in ER Model

(1) Ross, (2) Bachmann, (3) Martin (crow foot), (4) Chen, (5) Rumbaugh.

Page 10: Lecture 3a (1).ppt

Person, place, object, event or concept about which data is to be maintained

named property or characteristic of an entity

Association between the instances of one or more entity types

Represents a set or collection of objects in the real world that share the same properties

EntityName Verb Phrase AttributeName

Chen Notation

Page 11: Lecture 3a (1).ppt

11

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

Page 12: Lecture 3a (1).ppt

Entities – cont’d

• Examples of entities:– Person: EMPLOYEE, STUDENT, PATIENT– Place: STORE, WAREHOUSE– Object: MACHINE, PRODUCT, CAR– Event: SALE,REGISTRATION, RENEWAL– Concept: ACCOUNT, COURSE

• Guidelines for naming and defining entity types:– An entity type name is a singular noun– An entity type should be descriptive and specific – An entity name should be concise– Event entity types should be named for the result of the event, not

the activity or process of the event.

Page 13: Lecture 3a (1).ppt

13

Attributes

• Characteristics of entities

• 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 (oval also acceptable)

Page 14: Lecture 3a (1).ppt

Attributes – cont’d

• Example of entity types and associated attributes:STUDENT: Student_ID, Student_Name, Home_Address,

Phone_Number, Major

• Guidelines for naming attributes:– An attribute name is a noun.

– An attribute name should be unique

– To make an attribute name unique and clear, each attribute name should follow a standard format

– Similar attributes of different entity types should use similar but distinguishing names.

Page 15: Lecture 3a (1).ppt

15

Composite vs Simple Attributes

• Attributes can be simple OR composite• Composite attribute (NOT composite key) can be

subdivided to yield additional attributes. – an ADDRESS attribute can be subdivided into city,

state and postcode– NAME attribute can be subdivided into first_Name

and Last_Name• Simple attribute cannot be subdivided.

Ex. AGE, MARITAL STATUS

Page 16: Lecture 3a (1).ppt

16

Composite vs Simple Attributes

STUDENT

age name

fname

lname

Simple attribute

Composite attribute

Page 17: Lecture 3a (1).ppt

17

Single-Valued vs Multivalued Attributes

• Single-value attribute can have only a single value

Ex. CAR_MODEL_NO

• Not necessarily a simple attribute

Ex. IC_NUM => 780417-08-5284

is a composite attribute because it can be subdivided into birthdate (780417), place of birth (08), serial number (5284)

Multivalued attributes can have many values

Ex. A car color may be subdivided into many colors (colors for the roof, body and trim)

Chen Model, the multivalued attributes are shown by double line connecting the attribute to the entity.

Page 18: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 18

18

Multivalued Attributes (continued)

Page 19: Lecture 3a (1).ppt

19

Resolving Multivalued Attribute Problems

• Although conceptual model can handle multivalued attributes, you should not implement them in relational DBMS

– Option 1: Within original entity, create several new attributes, one for each of the original multivalued attribute’s components

• Can lead to major structural problems in table

– Option 2: Create new entity composed of original multivalued attribute’s components

Page 20: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 20

20

Resolving Multivalued Attribute Problems (continued)

Option 1: Within original entity, create several new attributes

Page 21: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 21

21

Resolving Multivalued Attribute Problems (continued)

Option 2: Create new entity composed of original multivalued attribute’s components

Page 22: Lecture 3a (1).ppt

Identifier vs non-identifierAttributes

• Non-identifier– Attribute which is not unique among instances of an entity

• Candidate key– Attribute (or combination of attributes) that uniquely identifies

each instance of an entity type

– Some entities may have more than one candidate key• Ex: A candidate key for EMPLOYEE is Employee_ID, a second is the

combination of Employee_Name and Address.• If there is more than one candidate key, need to make a choice.

• Identifier/primary key– A candidate key that has been selected as the unique identifying

characteristic for an entity type

Page 23: Lecture 3a (1).ppt

Example

Staff

StaffID

Name Gender

IC

Staff

StaffID

NameGenderIC

PK

Chen Notation

Crow’s Foot Notation

Page 24: Lecture 3a (1).ppt

Referential/foreign key Attributes

Name IdNum DeptID Email

Ali 105 LG [email protected]

Mary 106 IT [email protected]

John 107 ENG [email protected]

Lim 108 IT [email protected]

Name IdNum DeptID Email

Ali 105 LG [email protected]

Mary 106 IT [email protected]

John 107 ENG [email protected]

Lim 108 IT [email protected] of Lecturer.

Referential attribute: Ties the lecturer entity to another entity that is department.

• Make Reference to another instance in another table

Page 25: Lecture 3a (1).ppt

25

Derived Attributes

• Attribute whose value may be calculated (derived) from other attributes.

Ex. EMP_AGE can be derived by computing the difference between the current date and the EMP_DOB

• Need not be physically stored within database.• Can be derived by using an algorithm.• Chen Model, the derived attribute is connected to the

entity using dashed line.

Page 26: Lecture 3a (1).ppt

Relationships

Associations between instances of one or more entity types that is of interest

Given a name that describes its function.

• relationship name is an active or a passive verb.

Associations between instances of one or more entity types that is of interest

Given a name that describes its function.

• relationship name is an active or a passive verb.

Author Book

Relationship name: writes

An author writes one or more booksA book can be written by one or more authors.

Page 27: Lecture 3a (1).ppt

Degree of Relationships

• Degree: number of entity types that participate in a relationship

• Three cases– Unary: between two instances of one entity type– Binary: between the instances of two entity types– Ternary: among the instances of three entity types

Page 28: Lecture 3a (1).ppt

Cardinality and Connectivity

• Relationships can be classified as either • one – to – one• one – to – many• many – to –many

• Cardinality : minimum and maximum number of instances of Entity B that can (or must be) associated with each instance of entity A.

Connectivity

Page 29: Lecture 3a (1).ppt

Cardinality and Connectivity

Professor Classteaches

A professor teaches class ORA class is taught by professor

How Many??How Many??

Professor Classteaches

Page 30: Lecture 3a (1).ppt

Cardinality and Connectivity

Professor Classteaches

Professor Classteaches

1 M

Connectivity

Connectivity

(1,1)

(1,1)

(1,4)

(1,4)

Cardinality

Cardinality

Page 31: Lecture 3a (1).ppt

• Chen Model– 1 to represent one. – M to represent many

• Crow’s Foot

Connectivity

many

One

One or many

1

M

Mandatory one , means (1,1)

Optional? – we’ll see after this

Page 32: Lecture 3a (1).ppt

Binary Relationships

• 1:M relationship

– Relational modeling ideal

– Should be the norm in any relational database design

The 1: M relationship between PAINTER and PAINTING

Page 33: Lecture 3a (1).ppt

The Implemented 1:M relationship between PAINTER and PAINTING

Page 34: Lecture 3a (1).ppt

Binary Relationships

• 1:1 relationship – Should be rare in any relational database design

– A single entity instance in one entity class is related to a single entity instance in another entity class

– Could indicate that two entities actually belong in the same table

The 1:1 Relationship Between PROFESSOR and DEPARTMENT

Page 35: Lecture 3a (1).ppt

The Implemented 1:1 Relationship Between PROFESSOR and DEPARTMENT

Page 36: Lecture 3a (1).ppt

Binary Relationships

• M:N relationships

– Must be avoided because they lead to data redundancies.

– Can be implemented by breaking it up to produce a set of 1:M

relationships

– Can avoid problems inherent to M:N relationship by creating a

composite entity or bridge entity

• This will be used to link the tables that were originally related

in a M:N relationship

• The composite entity structure includes-as foreign keys-at

least the primary keys of the tables that are to be linked.

Page 37: Lecture 3a (1).ppt

The M:N Relationship Between STUDENT and CLASS

This CANNOT be implemented as shown next…..

Bowser

Smithson

Accounting 1 (ACCT-211)

Intro to Microcomputing (CIS-220)

Intro to Statistics (QM-261)

Page 38: Lecture 3a (1).ppt

The tables have many redundancies!!

+ CLASS_CODE

CLASS_CODE

+ STU_NUM

Page 39: Lecture 3a (1).ppt

Changing the M:N relationship to TWO 1:M relationships

Page 40: Lecture 3a (1).ppt

Converting the M:N relationship into TWO 1:M relationships

Foreign keys reference the primary keys in the other tables of which it has a relationship with

The database designer has 2 main options to define a composite table’s primary key: either

use the combination of those foreign keys or create a new primary key.

Page 41: Lecture 3a (1).ppt

Mandatory vs. Optional Cardinalities

• Specifies whether an instance must exist or can be absent in the relationship

Lecturer Classhandles

A Lecturer may handle zero or many classes.

A class is handled by one and only one Lecturer.

OptionalOptionalMandatoryMandatory

(0,N)(1,1)

Lecturer Class

(0,N) (1,1)

handles1 M

Page 42: Lecture 3a (1).ppt

42

Weak Entities

• Weak entity meets two conditions

– Existence-dependent• Cannot exist without entity with which it has a

relationship

– Has primary key that is partially or totally derived from parent entity in relationship

• Database designer usually determines whether an entity can be described as weak based on business rules

Page 43: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 43

43

Weak Entities (continued)

Page 44: Lecture 3a (1).ppt

44

Recursive Relationships

• Relationship type where same entity type participates more than once in different roles

• Relationship can exist between occurrences of the same entity set

• Naturally found within unary relationship

Page 45: Lecture 3a (1).ppt

Recursive Relationships

45

Page 46: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 46

46

Recursive Relationships (continued)

Page 47: Lecture 3a (1).ppt

ERD :: 19 / 1 / 07 47

47

Recursive Relationships (continued)

Page 48: Lecture 3a (1).ppt

How to Evaluate a Data Model?

• A good data model has the following:– Accuracy and completeness

– Non redundancy

– Enforcement of business rules

– Data Reusability

– Stability and Flexibility

– Communication Effectiveness

– Simplicity

Page 49: Lecture 3a (1).ppt

Lesson Summary

• ERD is a diagram that can be used to represent structure of a database.

• There are 3 main components of a database structure (1) entity (2) attribute (3) relationship

• All entities must be directly connected to at least one other entity in the ERD.