Top Banner
. Ms.V. Saranya AP/CSE Sri vidya college of Engg & Tech, Virudhunagar. diagram
61
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: Entity Relationship Model

.

Ms.V. Saranya AP/CSE

Sri vidya college of Engg & Tech, Virudhunagar.

diagram

Page 2: Entity Relationship Model

Objectives

• To illustrate how relationships between

entities are defined and refined.

• To know how relationships are incorporated

into the database design process.

• To describe how ERD components affect

database design and implementation

Page 3: Entity Relationship Model

Topics

• Design Process• Modeling• Constraints• E-R Diagram • Design Issues • Weak Entity Sets • Extended E-R Features

Page 4: Entity Relationship Model

DATAunorganized

form

ex: student’s score

Page 5: Entity Relationship Model

Informationprocessed, structured and organized

data ex: class average which can be

calculated from data.

Page 6: Entity Relationship Model

TABLEA table is a collection (rows) of data

on a single related topic.

Page 7: Entity Relationship Model

Difference between table and database

Table Database

A table is an object inside a database

A database has tables of data,

a table is a collection (rows) of data on a single related topic.

A database can have 10 or thousands of tables

Ex: employee tableContains only employees detail. But it not contains inventory detail.

But DB is a collection of Employee table as well as inventory table.

Page 8: Entity Relationship Model

Sample Table

Page 9: Entity Relationship Model

Sample Database DB is a collection

related tables

Page 10: Entity Relationship Model

Why we need ER diagramgiving you image of how the tables

should connect what fields are going to be on each table the tables connection, if many-to-many,

one-to-many.

“ER diagrams are easy for non-technical people to understand, and thus are typically used by database designers before the schema ever exists”

Page 11: Entity Relationship Model

Entity

• An entity is something that exists by itself.• Entity: Real-world object distinguishable from

other objects. An entity is described using a set of attributes.

Employees

ssnname

email

Page 12: Entity Relationship Model

Examples of entities

– Person: EMPLOYEE, STUDENT, PATIENT

– Place: STORE, WAREHOUSE

– Object: MACHINE, PRODUCT, CAR

– Event: SALE,REGISTRATION, RENEWAL

– Concept: ACCOUNT, COURSE

Page 13: Entity Relationship Model

Entity set

• Entity Set: A collection of similar entities. E.g., all employees. – All entities in an entity set have the same set of

attributes. – Each entity set has a key.– Each attribute has a domain.

Page 14: Entity Relationship Model

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

EntityName Verb Phrase AttributeName

Example

Page 15: Entity Relationship Model

RELATIONSHIP

• Relationship: Association among two or more entities. e.g., rose works in Pharmacy department.

• Relationship Set: Collection of similar relationships.

• Same entity set could participate in different relationship sets, or in different “roles” in same set.

Page 16: Entity Relationship Model

Relationship Example

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 17: Entity Relationship Model

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 18: Entity Relationship Model

Attributes• Example of entity types and associated attributes:

STUDENT: Student_ID, Student_Name, Home_Address, Phone_Number, Major

Page 19: Entity Relationship Model

Attribute types

– Simple and composite attributes.– Single-valued and multi-valued attributes• Example: multivalued attribute: phone_numbers

– Derived attributes• Can be computed from other attributes• Example: age, given date_of_birth

Page 20: Entity Relationship Model

A composite attribute

Page 21: Entity Relationship Model

Referential 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 22: Entity Relationship Model

Mapping Cardinality Constraints

• Express the number of entities to which another entity can be associated via a relationship set.

• Most useful in describing binary relationship sets.• For a binary relationship set the mapping

cardinality must be one of the following types:– One to one– One to many– Many to one– Many to many

Page 23: Entity Relationship Model

Mapping Cardinalities

One to one One to many

Note: Some elements in A and B may not be mapped to any elements in the other set

Page 24: Entity Relationship Model

Mapping Cardinalities

Many to one Many to many

Note: Some elements in A and B may not be mapped to any elements in the other set

Page 25: Entity Relationship Model

KEY

• Key and key attributes:– Key: a unique value for an entity– Key attributes: a group of one or more attributes that uniquely identify an

entity in the entity set• Super key, candidate key, and primary key

– Super key: a set of attributes that allows to identify and entity uniquely in the entity set

– Candidate key: minimal super key• There can be many candidate keys

– Primary key: a candidate key chosen by the designer• Denoted by underlining in ER attributes.

Page 26: Entity Relationship Model

Key Constraints

• Consider Works_In: An employee can work in many departments; a dept can have many employees.

• In contrast, each dept has at most one manager, according to the key constraint on Manages.

Page 27: Entity Relationship Model

Weak Entity Sets

• An entity set that does not have a primary key is referred to as a weak entity set.

• The existence of a weak entity set depends on the existence of a identifying entity set– it must relate to the identifying entity set via a total,

one-to-many relationship set from the identifying to the weak entity set

– Identifying relationship depicted using a double diamond

• The discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all the entities of a weak entity set.

• The primary key of a weak entity set is formed by the primary key of the strong entity set on which the weak entity set is existence dependent, plus the weak entity set’s discriminator.

Page 28: Entity Relationship Model

• In a relational database, a Weak Entity is an entity that cannot be uniquely identified by its attributes alone; therefore, it must use a foreign key in conjunction with its attributes to create a primary key. The foreign key is typically a primary key of an entity it is related to.

Page 29: Entity Relationship Model
Page 30: Entity Relationship Model

Conceptual design

• Conceptual design: (ER Model is used at this stage.)

• Process of describing the data, relationships between the data, and the constraints on the data.

Page 31: Entity Relationship Model

Entity-Relationship (ER) Diagram

• ER Modeling is a “top-down” approach to database design.

• Entity Relationship (ER) Diagram– A detailed, “logical representation” of the entities,

associations and data elements for an organization or business

Notation uses three main constructs– Data entities– Relationships– Attributes

Page 32: Entity Relationship Model

E-R Diagrams

Rectangles represent entity sets. Diamonds represent relationship sets. Lines link attributes to entity sets and entity sets to relationship sets. Ellipses represent attributes

Double ellipses represent multivalued attributes. Dashed ellipses denote derived attributes.

Underline indicates primary key attributes (will study later)

Page 33: Entity Relationship Model

E-R Diagram With Composite, Multivalued, and Derived Attributes

Page 34: Entity Relationship Model

Relationship Sets with Attributes

Page 35: Entity Relationship Model

Roles• Entity sets of a relationship need not be distinct• The labels “manager” and “worker” are called roles; they specify

how employee entities interact via the works_for relationship set.• Roles are indicated in E-R diagrams by labeling the lines that

connect diamonds to rectangles.• Role labels are optional, and are used to clarify semantics of the

relationship

Page 36: Entity Relationship Model

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 37: Entity Relationship Model

Cardinality Constraints• We express cardinality constraints by drawing

either a directed line (), signifying “one,” or an undirected line (—), signifying “many,” between the relationship set and the entity set.

• One-to-one relationship:– A customer is associated with at most one loan via

the relationship borrower– A loan is associated with at most one customer via

borrower

Page 38: Entity Relationship Model

One-To-Many Relationship

• In the one-to-many relationship a loan is associated with at most one customer via borrower, a customer is associated with several (including 0) loans via borrower

Page 39: Entity Relationship Model

Many-To-One Relationships

• In a many-to-one relationship a loan is associated with several (including 0) customers via borrower, a customer is associated with at most one loan via borrower

Page 40: Entity Relationship Model

Many-To-Many Relationship• A customer is associated with several (possibly 0)

loans via borrower• A loan is associated with several (possibly 0)

customers via borrower

Page 41: Entity Relationship Model

Connectivity

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

• Crow’s Foot

many

One

One or many

1

M

Mandatory one , means (1,1)

Page 42: Entity Relationship Model

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 43: Entity Relationship Model

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

Page 44: Entity Relationship Model

The 1:1 Relationship Between PROFESSOR and DEPARTMENT

Page 45: Entity Relationship Model

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 46: Entity Relationship Model

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 47: Entity Relationship Model

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

Page 48: Entity Relationship Model

Extended E-R

• Specialization• Generalization• Aggregation

Page 49: Entity Relationship Model

Specialization• Top-down design process: we designate sub

groupings within an entity set that are distinctive from other entities in the set.

• These sub groupings become lower-level entity sets that have attributes or participate in relationships that do not apply to the higher-level entity set.

• Depicted by a “triangle component labeled ISA”• Attribute inheritance – a lower-level entity set

inherits all the attributes and relationship participation of the higher-level entity set to which it is linked.

Page 50: Entity Relationship Model

Specialization Example

Page 51: Entity Relationship Model

Generalization• A bottom-up design process – combine a number of entity

sets that share the same features into a higher-level entity set.

• Specialization and generalization are simple inversions of each other; they are represented in an E-R diagram in the same way.

• The terms specialization and generalization are used interchangeably.

Page 52: Entity Relationship Model

Specialization and Generalization (Cont.)

• Can have multiple specializations of an entity set based on different features.

• E.g. permanent_employee vs. temporary_employee, in addition to officer vs. secretary vs. teller

• Each particular employee would be – a member of one of permanent_employee or

temporary_employee, – and also a member of one of officer, secretary, or teller

• The ISA relationship also referred to as “superclass – subclass” relationship

Page 53: Entity Relationship Model

Design Constraints on a Specialization/Generalization

• Constraint on which entities can be members of a given lower-level entity set.– Condition-defined : evaluated by an explicit condition or

predicate.– User-defined : database user assigns

• Constraint on whether or not entities may belong to more than one lower-level entity set within a single generalization.– Disjoint

• An entity can belong to only one lower-level entity set• Noted in E-R diagram by writing disjoint next to the ISA triangle

– Overlapping• an entity can belong to more than one lower-level entity set

Page 54: Entity Relationship Model

Design Constraints on a Specialization/Generalization (Contd.)

• Completeness constraint– Total : an entity must belong to one of the

lower-level entity sets– Partial : an entity need not belong to one of the

lower-level entity sets

Page 55: Entity Relationship Model

Aggregation Consider the ternary relationship works-on, which we saw earlier Suppose we want to record managers for tasks performed by an employee at a branch

Page 56: Entity Relationship Model

Aggregation (Cont.)• Relationship sets works_on and manages represent overlapping

information– Every manages relationship corresponds to a works_on relationship– However, some works_on relationships may not correspond to any

manages relationships • So we can’t discard the works_on relationship

• Eliminate this redundancy via aggregation– Treat relationship as an abstract entity– Allows relationships between relationships – Abstraction of relationship into new entity

• Without introducing redundancy, the following diagram represents:– An employee works on a particular job at a particular branch – An employee, branch, job combination may have an associated

manager

Page 57: Entity Relationship Model

Aggregation (Cont.)

• Relationship sets works-on and manages represent overlapping information– Every manages relationship corresponds to a works-

on relationship– However, some works-on relationships may not

correspond to any manages relationships we can’t discard the works-on relationship

• Redundancy problem aggregation

Page 58: Entity Relationship Model

E-R Diagram With Aggregation

Page 59: Entity Relationship Model

Summary of Symbols Used in E-R Notation

Page 60: Entity Relationship Model

Summary of Symbols (Cont.)

Page 61: Entity Relationship Model

Alternative E-R Notations