Transcript

Conceptual Modelling using ERD(with focus on Chen Notation)

Lesson 3

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

PRODUCT CUSTOMER

SUPPLIER

purchasedBy

suppliedBy

m n

1

m

prodID

name

price qtyBoughtcustID

name

contactNo

suppID

name address

contactNo

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.

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.

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.

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.

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.

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.

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

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

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.

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)

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.

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

16

Composite vs Simple Attributes

STUDENT

age name

fname

lname

Simple attribute

Composite attribute

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.

ERD :: 19 / 1 / 07 18

18

Multivalued Attributes (continued)

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

ERD :: 19 / 1 / 07 20

20

Resolving Multivalued Attribute Problems (continued)

Option 1: Within original entity, create several new attributes

ERD :: 19 / 1 / 07 21

21

Resolving Multivalued Attribute Problems (continued)

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

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

Example

Staff

StaffID

Name Gender

IC

Staff

StaffID

NameGenderIC

PK

Chen Notation

Crow’s Foot Notation

Referential/foreign key Attributes

Name IdNum DeptID Email

Ali 105 LG ali@a.com

Mary 106 IT mary@a.com

John 107 ENG john@a.com

Lim 108 IT lim@a.com

Name IdNum DeptID Email

Ali 105 LG ali@a.com

Mary 106 IT mary@a.com

John 107 ENG john@a.com

Lim 108 IT lim@a.comInstance of Lecturer.

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

• Make Reference to another instance in another table

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.

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.

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

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

Cardinality and Connectivity

Professor Classteaches

A professor teaches class ORA class is taught by professor

How Many??How Many??

Professor Classteaches

Cardinality and Connectivity

Professor Classteaches

Professor Classteaches

1 M

Connectivity

Connectivity

(1,1)

(1,1)

(1,4)

(1,4)

Cardinality

Cardinality

• 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

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

The Implemented 1:M relationship between PAINTER and PAINTING

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

The Implemented 1:1 Relationship Between PROFESSOR and DEPARTMENT

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.

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)

The tables have many redundancies!!

+ CLASS_CODE

CLASS_CODE

+ STU_NUM

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

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.

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

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

ERD :: 19 / 1 / 07 43

43

Weak Entities (continued)

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

Recursive Relationships

45

ERD :: 19 / 1 / 07 46

46

Recursive Relationships (continued)

ERD :: 19 / 1 / 07 47

47

Recursive Relationships (continued)

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

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.

top related