0% found this document useful (0 votes)
17 views53 pages

Unit-1 E-R Model-30slides 9 Sept24

The document provides an overview of the Entity-Relationship (ER) model, which is a graphical representation of entities and their relationships used for database design. It discusses the advantages and disadvantages of the ER model, the definitions of entities and attributes, types of relationships, and the concept of cardinality. Additionally, it introduces advanced concepts such as generalization, specialization, and aggregation within the enhanced ER model.

Uploaded by

Shitiz Saini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views53 pages

Unit-1 E-R Model-30slides 9 Sept24

The document provides an overview of the Entity-Relationship (ER) model, which is a graphical representation of entities and their relationships used for database design. It discusses the advantages and disadvantages of the ER model, the definitions of entities and attributes, types of relationships, and the concept of cardinality. Additionally, it introduces advanced concepts such as generalization, specialization, and aggregation within the enhanced ER model.

Uploaded by

Shitiz Saini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 53

E-R Model

• definition -
• The entity-relationship model (or ER
model) is a way of graphically representing
the logical relationships of entities (or
objects) in order to create a database. The
ER model was first proposed by Peter Pin-
Shan Chen of Massachusetts Institute of
Technology (MIT) in the 1970s
id
Entity-Relationship Model
employee working Department Name

Name

Deptn Dateo Locati deptti


Empd Enam Salary deptid
ame f on d
id e
joinin
g
Advantages of ER Model

• Conceptually it is very simple – Making the ER Diagram is a very easy


process. You just know about the notations about various types of entities,
their attributes and the relationships between these entities.
• Better visual representation – The E-R model gives graphical and
diagrammatical representation of various entities, their attributes and
relationships between entities. So, It helps in the clear understanding of the
data structure and in minimizing redundancy and other problems.
• Effective Communication Tool – It is an effective communication tool
among users, domain experts ans database designers.
• It is highly integrated with relational model, so converting ER Diagrams
to tables is very simple.
• Easy conversion to any Data Model – Conversion of ER Diagram to any
other data model like network model, hierarchical model and the relational
model is very easy.
Disadvantages of ER Model

• Limited Constraints and Specifications – Example :


minimum Cardinality.
• No industry standard for notation – i.e. there is no
industry standard notation for developing an E-R
diagram.
• Popular for high-level design – The E-R data model is
especially popular for high level design.

• No representation of data manipulation


Entity
• An entity is an object that exists and is
• distinguishable from other objects.

• Might be
• Object with physical existence like
Lect,student,car.
• Object with conceptual or logical existence
like course,job,postion.
– An ENTITY SET is a set of entities of the same type that
share the same properties.
– Example:, companies, trees, Employee etc

E1.

E2 REPRESENT IN

E3 E-R DIAGRAM EMPLOYEE

E4

Rectangles represent entity type

Entity Type:- a collection of similar entities


• A set of entities that have • The individual entities of a
the same attributes is particular entity type are
grouped into a collection or
called an entity type. entity set, which is also called
Each entity type in the the extension of the entity type.
database is described by
a name and a list of • An entity is a thing in the real
attributes. For example world. It may be an object with
a physical existence or an
an entity employee is an object with a conceptual
entity type that has existence. A set of these
Name, Age and Salary entities having same attributes
attributes. is entity type and collection of
individual entity type is an entity
set.
ENTITY SET corresponding to the
ENTITY TYPE CAR
CAR
Registration(RegistrationNumber, State), VehicleID, Make, Model, Year, (Color)

car1
((ABC 123, TEXAS), TK629, Ford Mustang, convertible, 1999, (red, black))
car2
((ABC 123, NEW YORK), WP9872, Nissan 300ZX, 2-door, 2002, (blue))
car3
((VSY 720, TEXAS), TD729, Buick LeSabre, 4-door, 2003, (white, blue))
.
.
.
empid, empname, deptt------entity type
Gaurav,cse,11
Rajiv,cse,12
entity is a thing in the real world with an independent
existance. and entity set is collection or set all entities of a
particular entity type at any point of time.
take an example:
a company have many employees ,and these employees
are defined as entities(e1,e2,e3....) and all these entities
having same attributes are defined under ENTITY TYPE
employee.and set{e1,e2,.....} is called entity set.

we can also understand this by an anology .

entity type is like fruit which is a class .we havn't seen any
"fruit"yet though we have seen instance of fruit like
"apple ,banana,mango etc.hence..
fruit=entity type=EMPLOYEE
apple=entity=e1 or e2 or e3
enity set= bucket of apple,banana ,mango etc={e1,e2......}
• STRONG ENTITY SETS
An entity set containing a key attribute are called strong
entity types or regular entity types.
For example, The STUDENT entity has a key attribute
Roll No which uniquely identifies it, hence is a strong
entity set.
id emp

• WEAK ENTITY SETS


An entity set may not have sufficient attribute to form a
primary key. Entity types that do not contain any key
attributes, and hence can not be identified independently
are called weak entity sets.
• A weak entity can be identified uniquely only by
considering some of its attributes in conjunction with the
primary key attribute of another entity, which is called the
identifying owner entity
color
table
Attributes
• Attributes are properties used to describe an
entity. For example an EMPLOYEE entity may
have a Name, SSN, Address, Sex, BirthDate.

• Attribute Domain: The set of allowable values


for one or more attributes.

• Attributes can be classified as being: simple or


composite; single-valued or multi-valued; or
derived.
Types of Attributes (1)
• Simple
– Each entity has a single atomic value for the attribute. For
example, SSN or Sex.
• Composite
– The attribute may be composed of several components. For
example, Address (Apt#, House#, Street, City, State,
ZipCode, Country) or Name (FirstName, MiddleName,
LastName). Composition may form a hierarchy where some
components are themselves composite.
• Multi-valued
– An entity may have multiple values for that attribute. For
example, Color of a CAR or mobile no.
Types of Attributes (2)
• Single values:- attribute that have only one value for
each entity e.g. name,age for employee.

• Derived:-attribute contain values that are derived from


other attributes e.g. age can be derived from DOB &
current date
• Null Value :- unknown value e.g. PF no. of employee

STORED ATTRIBUTE:-Attributes that are directly


stored in the database and can not derived from other
one are called stored attributes .
For example, Birth Date attribute of a STUDENT entity
SUMMARY OF ER-DIAGRAM
NOTATION FOR ER SCHEMAS
Symbol Meaning

ENTITY TYPE

WEAK ENTITY TYPE

RELATIONSHIP TYPE

IDENTIFYING RELATIONSHIP TYPE

ATTRIBUTE

KEY ATTRIBUTE

MULTIVALUED ATTRIBUTE

COMPOSITE ATTRIBUTE

DERIVED ATTRIBUTE

E1 R E2 TOTAL PARTICIPATION OF E2 IN R

E1 N
R E2
CARDINALITY RATIO 1:N FOR E 1:E2 IN R
(min,max)
R E STRUCTURAL CONSTRAINT (min, max) ON
PARTICIPATION OF E IN R
Relationships and Relationship
Types (1)
• A relationship relates two or more distinct entities with a
specific meaning. For example, EMPLOYEE John
Smith works on the ProductX PROJECT or EMPLOYEE
Franklin Wong manages the Research DEPARTMENT.
Example relationship instances of the WORKS_FOR
relationship between EMPLOYEE and DEPARTMENT
EMPLOYEE WORKS_FOR DEPARTMENT

r1
e1   d1

e2  r2

e3  r3  d2

e4  r4
 d3
e5 
r5
e6 
r6
e7 
r7
Degree of a Relationship Type
• The degree of a relationship type is the number
of participating entity types.

• unary(recursive) relationship type :- that


involves only one entity.

• Binary relationship type :-has 2 entity type link


together.

• Ternary:- if there are 3 entity type link toghter.


Mapping Cardinalities
• 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
• A one to one relationship - a man can only
marry one woman, and a woman can only marry
one man, so it is a one to one (1:1) relationship
• A one to may relationship - one manager
manages many employees, but each employee
only has one manager, so it is a one to many (1:n)
relationship
• A many to one relationship - many students
study one course. They do not study more than
one course, so it is a many to one (m:1)
relationship
• A many to many relationship - One lecturer
teaches many students and a student is taught by
many lecturers, so it is a many to many (m:n)
relationship
What is the ER Model?
• ENTITY RELATIONAL (ER) MODEL is a
high-level conceptual data model diagram.
• ER modeling helps you to analyze data
requirements systematically to produce a
well-designed database.
• The Entity-Relation model represents real-
world entities and the relationship between
them. It is considered a best practice to
complete ER modeling before implementing
your database.
• .
Components of the ER Diagram
• This model is based on three basic concepts:
• Entities
• Attributes
• Relationships

• Example
• For example, in a University database, we might
have entities for Students, Courses, and
Lecturers. Students entity can have attributes like
Rollno, Name, and DeptID. They might have
relationships with Courses and Lecturers.
• Examples of entities:
• Person: Employee, Student, Patient
• Place: Store, Building
• Object: Machine, product, and Car
• Event: Sale, Registration, Renewal
• Concept: Account, Course
One to One Relationship
• When a single instance of an entity is associated with a single
instance of another entity then it is called one to one relationship.
For example, a person has only one passport and a passport is
given to one person.
One to Many Relationship

• When a single instance of an entity is associated with more than


one instances of another entity then it is called one to many
relationship. For example – a customer can place many orders but a
order cannot be placed by many customers.
Many to One Relationship

• When more than one instances of an entity is associated


with a single instance of another entity then it is called
many to one relationship. For example – many students
can study in a single college but a student cannot study
in many colleges at the same time.
Many to Many Relationship

• When more than one instances of an entity is associated


with more than one instances of another entity then it is
called many to many relationship. For example, a can be
assigned to many projects and a project can be assigned
to many students.
Participation constraints in DBMS

• in a Relationship, Participation constraint specifies the


presence of an entity when it is related to another entity
in a relationship type. It is also called the minimum
cardinality constraint.

• There are two types of Participation constraint:


– Total participation
– Partial participation
Total Participation of an Entity
set
• A Total participation of an entity set represents that each
entity in entity set must have at least one relationship in
a relationship set. For example: In the below diagram
each college must have at-least one associated Student.
Total participation constraint
• In total participation, Each entity is involved in the relationship and is
represented by double lines.it,for this reason, it is also called as
mandatory participation
Partial participation
• In partial participation, Not all entities are involved in the relationship
and is represented by single lines.
• Example of partial participation
• A single line between the entities i.e courses and enrolled in a
relationship signifies the partial participation,which means there
might be some courses where enrollments are not made i.e
enrollments are optional in that case
Extended(Enhanced ) ER Model:

• The ER modeling concepts are sufficient for representing


traditional database application. For more complex
database application such as telecommunications ,
CAD/CAM , GIS etc , we need more complex
requirements than traditional applications. In late 1970’s
database designers have tried to design more accurate
ER model , which reflects the data properties and
constraints more accurately . So extended(Enhanced )
ER model have some enhanced features than normal
ER model. It uses the concepts of Specialization ,
Generalization , Aggregation
Generalization:

• Generalization is just reverse of Specialization.


Generalization is the process to define a
generalized entity type from the given entity
type. For ex. Consider the two entity CAR and
TRUCK . Because both have some common
attributes, they can combindly make a super
entity called VEHICLE. So it is the process to
identify the common features (attributes) from
• two or more entity and generalized them into a
super entity.
Note:
1. Generalization uses bottom-up
approach where two or more lower
level entities combine together to
form a higher level new entity.

2. The new generalized entity can


further combine together with lower
level entity to create a further higher
level generalized entity.
Specialization:
• Specialization is a process in which an entity is
divided into sub-entities. You can think of it as a
reverse process of generalization, in
generalization two entities combine together to
form a new higher level entity. Specialization is a
top-down process. For ex. An entity “employee”
has the sub entity , ‘faculty’, ‘Staff’. So employee
has the relation with both the sub entity. This
relation name is “IS A”. as shown in fig. So
Specialization follow the process of one to many
relationship
n the above diagram, we can see that
we have a higher level entity
“Employee” which we have divided in
sub entities “Technician”, “Engineer” &
“Accountant”. All of these are just an
employee of a company, however their
role is completely different and they
have few different attributes. Just for the
example,
I have shown that Technician handles
service requests,
Engineer works on a project and
Accountant handles the credit & debit
details.

All of these three employee types have


few attributes common such as name &
salary which we had left associated with
the parent entity “Employee” as shown
in the above diagram.
Aggregation:
• Aggregation is a process in which a
single entity alone is not able to make
sense in a relationship so the
relationship of two entities acts as
one entity. I know it sounds confusing
but don’t worry the example we will
take, will clear all the doubts.
• .
In real world, we know that a
manager not only manages the
employee working under them but
he has to manage the project as
well. In such scenario if entity
“Manager” makes a “manages”
relationship with either
“Employee” or “Project” entity
alone then it will not make any
sense because he has to manage
both. In these cases the
relationship of two entities acts as
one entity. In our example, the
relationship “Works-On” between
“Employee” & “Project” acts as
one entity that has a relationship
“Manages” with the entity
“Manager
Hospital ER Model

Each of these entities have their respective attributes which are −


•Patients - ID(primary key), name, age,visit_date
•Tests- Name(primary key), date, result
•Doctor- ID(primary key), name, specialization
Company ER Model

•Employee - ENO(Primary Key) , Name, Salary


•Department - DNO(Primary key), Name, Locations
•Project - PNO(Primary key), Name
• ER diagram of Company has the following description :
• Company has several departments.
• Each department may have several Location.
• Departments are identified by a name, D_no, Location.
• A Manager control a particular department.
• Each department is associated with number of projects.
• Employees are identified by name, id, address, dob, dat
e_of_joining.
• An employee works in only one department but can work on several
project.
• We also keep track of number of hours worked by an employee on a
single project.
• Each employee has dependent
• Dependent has D_name, Gender and relationship.
• Entities and their Attributes are
• Employee Entity : Attributes of Employee Entity are
Name, Id, Address, Gender, Dob and Doj.
Id is Primary Key for Employee Entity.
• Department Entity : Attributes of Department Entity are
D_no, Name and Location.
D_no is Primary Key for Department Entity.
• Project Entity : Attributes of Project Entity are P_No,
Name and Location.
P_No is Primary Key for Project Entity.
• Dependent Entity : Attributes of Dependent Entity are
D_no, Gender and relationship.
• Relationships are :
• Employees works in Departments –
Many employee works in one Department but one employee can not
work in many departments.
• Manager controls a Department –
employee works under the manager of the Department and the
manager records the date of joining of employee in the department.
• Department has many Projects –
One department has many projects but one project can not come
under many departments.
• Employee works on project –
One employee works on several projects and the number of hours
worked by the employee on a single project is recorded.
• Employee has dependents –
Each Employee has dependents. Each dependent is dependent of
only one employee.
Practice
• Construct an E-R diagram for a car-
insurance company whose customers own
• one or more cars each. Each car has
associated with it zero to any number of
• recorded accidents.
• Construct an E-R diagram for a hospital
with a set of patients and a set of medi-
• cal doctors. Associate with each patient a
log of the various tests and examina-
• tions conducted.

You might also like