0% found this document useful (0 votes)
104 views65 pages

Entity - Relationship Model - CH2

The document describes the entity-relationship (ER) model, which is a high-level conceptual data model used to define the data elements and relationships within a system. The ER model develops a conceptual design for the database and defines entities (objects, people, places), attributes (properties of entities), and relationships between entities. Common entity types in examples include students, courses, teachers, etc. Relationships can be one-to-one, one-to-many, many-to-one, or many-to-many. The ER model forms the basis for developing a relational database schema.

Uploaded by

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

Entity - Relationship Model - CH2

The document describes the entity-relationship (ER) model, which is a high-level conceptual data model used to define the data elements and relationships within a system. The ER model develops a conceptual design for the database and defines entities (objects, people, places), attributes (properties of entities), and relationships between entities. Common entity types in examples include students, courses, teachers, etc. Relationships can be one-to-one, one-to-many, many-to-one, or many-to-many. The ER model forms the basis for developing a relational database schema.

Uploaded by

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

CH 2

The Entity-
Relationship Model
The Entity- Relationship Model

● ER model stands for an Entity-Relationship model. It is a high-level


data model. This model is used to define the data elements and
relationship for a specified system.

● It develops a conceptual design for the database. It also develops a


very simple and easy to design view of data.
Example - Suppose we design a school database. In this database, the student
will be an entity with attributes like address, name, id, age, etc. The address
can be another entity with attributes like city, street name, pin code and there
will be a relationship between them.
Entity:
● An entity may be any object, class, person or place. In the
ER diagram, an entity can be represented as rectangles.

● Consider an organization - manager, product, employee,


department etc can be taken as an entity.
● An entity that depends on another entity called a weak entity.

● The weak entity doesn't contain any key attribute of its own.
The weak entity is represented by a double rectangle.
Attributes:
● Attributes are the properties which define the entity type.

● Example - Roll_No, Name, DOB, Age, Address,


Mobile_No are the attributes which defines entity type
Student.

● In ER diagram, attribute is represented by an oval.


Example - id, age, contact number, name, etc. can be attributes
of a student.
1. Composite Attribute -
● An attribute that composed of many other attributes is known as a
composite attribute.
● The composite attribute is represented by an ellipse, and those ellipses
are connected with an ellipse.
2. Multivalued Attribute
● An attribute can have more than one value.
● These attributes are known as a multivalued attribute.
● The double oval is used to represent multivalued attribute.
Example - student can have more than one phone number.
3. Derived Attribute
● An attribute that can be derived from other attribute is known as a
derived attribute. It can be represented by a dashed ellipse.
● Example - A person's age changes over time and can be derived
from another attribute like Date of birth.
Relationship
● A relationship is used to describe the relation between entities.

● Diamond or rhombus is used to represent the relationship.


Types of relationship are as follows:
1. One-to-One Relationship
● When only one instance of an entity is associated with the relationship,
then it is known as one to one relationship.

● Example - A female can marry to one male, and a male can marry to one
female.
2. One-to-many relationship

● When only one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then this
is known as a one-to-many relationship.

● Example - Scientist can invent many inventions, but the invention is done
by the only specific scientist.
3. Many-to-one relationship
● When more than one instance of the entity on the left, and only one
instance of an entity on the right associates with the relationship then
it is known as a many-to-one relationship.

● Example - Student enrolls for only one course, but a course can have
many students.
4. Many-to-many relationship
● When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.

● Example - Employee can assign by many projects and project can


have many employees.
Notation of ER diagram

● Database can be represented


using the notations.
● These notations are as follows:
Mapping Constraints
● A mapping constraint is a data constraint that expresses the number of
entities to which another entity can be related via a relationship set.

● For binary relationship set R on an entity set A and B, there are four
possible mapping cardinalities. These are as follows:
One to one (1:1)
One to many (1:M)
Many to one (M:1)
Many to many (M:M)
One-to-one

In one-to-one mapping, an entity in E1 is associated with at most one


entity in E2, and an entity in E2 is associated with at most one entity in
E1.
One-to-many

In one-to-many mapping, an entity in E1 is associated with any


number of entities in E2, and an entity in E2 is associated with at most
one entity in E1.
Many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one
entity in E2, and an entity in E2 is associated with any number of
entities in E1.
Many-to-many

In many-to-many mapping, an entity in E1 is associated with any number


of entities in E2, and an entity in E2 is associated with any number of
entities in E1.
Relational Model
● A relational database is a collection of 2-dimensional tables which
consists of rows and columns.

● Tables are known as “relations”.

● Column are known as “attributes”.

● Rows(records) are known as “tuples”.


Hospital ER Model
Company ER Model
ER diagram of the music database
ER diagram of the university database
ER diagram of the flight database
ER Diagram of Library Management System
EER Model
EER model includes all modelling concept of ER model.

EER Features -
● Subclass and Superclass
● Specialization and Generalization
● Union and category
● Aggregate
Super Class
● The class which is having its sub groupings called as super
class.

● An entity cannot exist in database merely by being member


of any superclass.

● Example - employee super class is having sub groupings as


technician, secretary and developer.
Sub Class
● The class which is a sub grouping of other class is called
subclass.
● A subclass is more specific version of its superclass.
● A subclass is a class that inherits properties and attributes
from its superclass.

● Example - Bus, Car and Bike are subclass of vehicle


superclass.
Generalization
● It is a process of generalizing two or more lower-level entity
types into a higher-level entity type.
● In this process, the common attributes of two or more entities
combine to form a new entity type.
● The new entity type formed is called a generalized entity.
● It is a bottom-up approach.
● Example - Whales, Sharks, and Dolphins can be generalized as
Fish. Similarly, Bicycle, Bike, and Car can be generalized as
Vehicles.
Generalization
Specialization
● It is a process of specializing an entity type into a more specified entity.
● In this process, we specialize a higher-level entity type by adding some
additional attributes to the entity.
● It is a top-down approach in which a higher-level entity is broken into
smaller entities.

● Example, Animals can be mammals or reptiles. Then these mammals can


either be tiger, elephant or humans. The reptiles can be snakes or lizards
type.
Aggregration

● Aggregation is a process in which a single entity does not work so the


relationship of two entities acts as one entity.

● Aggregation is an abstraction through which we can represent


relationships as higher level entity sets.

● Aggregation is a concept which is used when the ER model cannot


represent the relationship between an entity and the relationship.
● In aggregation, the relation between two entities is treated as a
single entity. In aggregation, relationship with its corresponding
entities is aggregated into a higher level entity.

● It is used when we need Express a relationship among other


relationships.

● In DBMS, we need to find the sum of salaries of all the employees


working in an organization or to find the highest-paid employee from
all branches of the organization etc.
Design steps for Aggregation

1. Define entities and their attributes.

2. Add a relationship between these entities.

3. Define another entity so that the relationship can be


established between the existing relationship and this entity.
To calculate aggregate values, one requires some aggregate operators:

1. COUNT – To calculate the number of values present in a particular


column.
2. SUM – To calculate the sum of all the values present in a particular
column.
3. AVG – To calculate the average of all the values present in a particular
column.
4. MAX – To find the maximum of all the values present in a particular
column.
5. MIN – To find the minimum of all the values present in a particular
column.
Example: Find the average salary of all the employees.

SELECT AVG (E.salary) FROM Employee E


1. SELECT MAX (Marks) FROM Student S WHERE Section = 'A'
2. SELECT MAX (Marks) FROM Student S WHERE Section = ‘A’
HAVING Marks > 90
Relationship Types of Degree

Degree of relationship type


● The degree of relationship type is number of participating
entity types.
● Types
○ Binary Relationship Type
- A relationship of degree two
○ Ternary Relationship Type
- A relationship of degree three
● N-ary (n degree)
- There are n types of entity that associates.

Example: We have 5 entities Teacher, Class, Location, Salary, Course. So, here
five entity types are associating we can say an n-ary relationship is 5.
Problems

1. Draw ER Diagram for car insurance company that has a set of


customer each of whose having one or more car. Each car
associated with it zero to any number of records accidents.
2. Construct an ER Diagram for hospital with a set of patients and
the set of medical doctors associated with each patient a record of
various text and examination conducted.
3. Draw ER Diagram for University database consisting for Entities
student, department , class and faculty.
● Student has an unique id, the student can enroll for multiple classes
and has a most one major.
● Faculty must belong to department and faculty can teach multiple
classes.
● Each class is taught by only faculty.
● Every student will get grade for the class he/she has enrolled.
4. Design a database to keep track of information for an art museum.
Assume the following requirements were collected
● Museum has collection of ART_OBJECTS. Each ART_OBJECT has a
unique IDno, artist , year , title and description. The art objects are
categorized in several ways.
● ART_OBJECTS are categorized based on their type.There are three
main types: PAINTING, SCULPTURE AND STATUE, plus another
type called OTHER to accommodate objects that do not fall into one of
the three main types.
● PAINTING has a type , material and style.
● SCULPTURE or STATUE has material from which it is created,
height, weight and style.
● An art object in the OTHER category has a type and style.
Types of Participation Constraints-
There are two types of participation constraints-
1.Total Participation-
● It specifies that each entity in the entity set must compulsorily
participate in at least one relationship instance in that relationship set.

● That is why, it is also called as mandatory participation.

● Total participation is represented using a double line between the


entity set and relationship set.
2. Partial Participation-

● It specifies that each entity in the entity set may or may not
participate in the relationship instance in that relationship set.

● That is why, it is also called as optional participation.

● Partial participation is represented using a single line between


the entity set and relationship set.
Relationship between Cardinality and Participation Constraints-

Minimum cardinality tells whether the participation is partial or total.

● If minimum cardinality = 0, then it signifies partial participation.


● If minimum cardinality = 1, then it signifies total participation.

Maximum cardinality tells the maximum number of entities that participates


in a relationship set.
Questions
1. Write a note on :
Weak entity, Specialization and Generalization.
2. Write short note on :
Total participation , Partial participation
3. Define Degree.
4. Explain : Extended E-R features

You might also like