Entity Relationship Model · Entity Relationship Model Logical representation of data for an...

20
Entity Relationship Model Database System

Transcript of Entity Relationship Model · Entity Relationship Model Logical representation of data for an...

Page 1: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Model

Database System

Page 2: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Model

Logical representation of data for an organization.

It views the entire system as a collection of entities related to one

another.

It is used to describe the elements of a system and their relationships.

Provide a graphical notation for representing data models in the form

of a diagram called Entity Relationship Diagram (ERD).

Page 3: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

ERD represents 3 components:

◦ Entities

◦ Attributes

◦ Relationship

Entities: A person, place or thing about which the organization

wishes to maintain data. E.g: Teacher, Student (Person), Country , City

(Place), Toy (thing).

In ER Modeling , entity refers to entity set & not single entity instance.

In other words, in Relational Modeling, Entity refer to table not single

row

Page 4: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Entities:

For example: Student is a entity type which is a set of all students.

In ERD, Entity is represented by:

Entity

Weak Entity

Composite Entity

Page 5: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Attributes:

A property or characteristics of an entity type that is of interest to the

organization.

For example: st_name, marks, age are the attributes of Student entity.

In ERD, Attribute is represented by:

Simple Attribute

Multi valued Attributes

Derived Attributed

Page 6: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Relationships:

Association between entities are called Relationship.

It operate in both directions.

In ERD, Relationships are represented by:

Simple Relationship

Identifying Relationship

Page 7: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Identifying Relationship:

An identifying relationship means that the child table cannot be

uniquely identified without the parent. For example, you have this

situation in the intersection table used to resolve a many-to-many

relationship where the intersecting table's Primary Key is a

composite of the left and right (parents) table's Primary Keys.

Example...

Page 8: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Cardinalities:

Number of tuples of one entity that can be associated with each tuple

of an other entity:

Mandatory One

Mandatory Many

Option one

Optional many

Page 9: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Entity Relationship Diagram

Degree of a Relationship

Degree of a relationship is the number of entities

involved in a relationship.

Special cases are unary, binary, and ternary ,where the

degree is 1, 2, and 3, respectively.

The relationship of degree 2 (Binary) are most commonly

used.

• Example for unary relationship : An employee is a manager

of another employee

• Example for binary relationship : An employee works-for

department.

• Example for ternary relationship : customer purchase item

from a shop keeper

Page 10: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Degree of a Relationship

The types of relationships with respect to degrees:

1. Unary Relationship

2. Binary Relationship

3. Ternary Relationship

Page 11: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Unary Relationship

• It is a type of relationship that is established between

instances of same entity type.

• This is also called recursive relationship.

• Example:

Person Lives with

Page 12: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

It is a type of relationship that is established between instances of

two different entity type.

o This leads to three possible associations between data items:

o One to One (I:I)

o One to many (I:M)

o Many to Many (M:N)

Page 13: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oOne to One (I:I)

In this case,

“for each instance in first entity class, there is only one instance

in the second entity class and for each instance in second

entity class, there is only one instance in the first entity class”

This relationship means that one chairman runs only one

department, similarly one department is run by one chairman.

Chairman Runs Department

Page 14: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oOne to One (I:I)

Other Examples:

s

This relationship means that one country has only one President, Similarly

one President is of only one country.

This relationship means that one manager manages only one Branch of a

bank, Similarly one branch of a bank is managed by one manager.

.

manages

Country has President

Branch Manager

Page 15: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oOne to Many (I:M)

In this case,

“for each instance in first entity class, there can be many

instances in the second entity class and for each instance in

Second entity class, there is only one instance in the first entity

class”

This relationship means that one state can have many cities

but one city is belonged to one state.

State has City

Page 16: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oOne to Many (I:M)

Other Examples:

s

This relationship means that one University has many Deprtments, But

one department is a part of only one University.

.

University has Department

Page 17: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oMany to Many (M:N)

In this case,

“for each instance in first entity class, there can be many

instances in the second entity class and for each instance in

Second entity class, there can be many instances in the first

Entity class”

This relationship means that one student may study many

courses and one course may be studied by many students.

Student studies Course

Page 18: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Binary Relationship

oMany to Many (M:N)

This relationship means that one employee can learn many

skills and one skill can be learned by many employees.

Reader reads Book

Employee learn Skill

This relationship means that one reader may read many books

and one book may be read by many readers.

Page 19: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Ternary Relationship

• Ternary relationship exists among the instances of

three entity types.

This relationship means that one or many consultants with one

or many clients signs on one or many contracts.

Consultant signs Client

Contract

Page 20: Entity Relationship Model · Entity Relationship Model Logical representation of data for an organization. It views the entire system as a collection of entities related to one another.

Ternary Relationship

• Ternary relationship exists among the instances of

three entity types.

This relationship means that one or many anylsts with one

or many programmers works on one or many projects.

Analyst Works

on Programmer

Project