0% found this document useful (0 votes)
40 views27 pages

DBMS UNIT 2 New

database unit 2

Uploaded by

Vishnu Rajeev
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)
40 views27 pages

DBMS UNIT 2 New

database unit 2

Uploaded by

Vishnu Rajeev
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/ 27

UNIT-2

ENTITY RELATIONSHIP MODEL

1) Explain the basic building blocks of ER model.


ER Model:

 It was introduced by Peter chen in 1976.


 It describes the structure of Database with the help of diagrams , which
is known as ERD (Entity Relationship Diagrams).
 It is a blue-print or design of Database that can later be implemented as
Database.
 The Entity Relationship Model is a model for identifying entities (like
student, car or company) to be represented in the database and
representation of how those entities are related. The ER data model
specifies enterprise schema that represents the overall logical structure
of a database graphically.
 ER diagrams represent the E-R model in a database, making them easy
to convert into relations (tables).
 ER diagrams provide the purpose of real-world modeling of objects which
makes them intently useful.
Advantages:
 It is an effective communication tool.
 ER diagrams are very easy to translate into relational tables which can be used to
quickly build databases.
Symbols Used in ER Model
ER Model is used to model the logical view of the system from a data perspective
which consists of these symbols:
 Rectangles: Rectangles represent Entities in the ER Model.
 Ellipses: Ellipses represent Attributes in the ER Model.
 Diamond: Diamonds represent Relationships among Entities.
 Lines: Lines represent attributes to entities and entity sets with other
relationship types.
 Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
 Double Rectangle: Double Rectangle represents a Weak Entity.

1
Basic building blocks of ER Model:
The basic building blocks of ER-Model are

1. Entity 2. Attributes 3.Constraints 4.Relationships

Entity: An entity is defined as real world object. It can be anything like a student,
faculty, doctor, patient, product etc., An entity stores collection of records. An
entity is represented by “rectangle” symbol in a database design.

Entity
Attribute: Attributes is defined as a character or a group of characters that has a
specific meaning. It is also known as “Field”. An attribute is represented by “oval”
symbol in a database design.

Attribute

Constraints: Constraints are “set of rules” which we enforce on data in a


database.
Relationship: A relationship is defined as an association among entities. A
relationship is represented by “diamond” symbol in a database design.

Relationship
Types of Relationships: There are four types of relationships they are:

1. one-to-one (1:1or1.1)
2. one-to-many (1:Mor1..*)
3. Many-to-one (M:1)
4. many-to-many (M:Nor*..*)

ER Notations: The entities and their relationships are represented with the notations
of ER model.
They are two different types of ER notations
1. Chen’s notations
2. Crow’s Foot notations
1. Chen’s notations:
1 1
Employee Department
belongs

1 M
Manager Super Department

M M
Employee involve Project

2. Crow’s Foot notations:

 It was developed by Gordan Everest.


 In this notation,the entity is represented with rectangle box.

Student 1 M skills Employee M M Project

Employee 1 1 Department

3
2. Explain about the classification of Entity sets
Classification of Entity Sets:
Entity: An Entity is an object that is represented in the database.
Ex: person, place, thing etc.
Types of Entities:
Entities based on their characteristics are classified as follows:
1. Strong entity type
2. Weak entity type
3. Recursive entity type

1. StrongEntitytype:
 A Strong Entity is a type of entity that has a key Attribute.
 Strong Entity does not depend on other Entity in the Schema.
 It has a primary key, that helps in identifying it uniquely, and it is
represented by a rectangle. These are called Strong Entity Types.
 The member of strong entity set is known as Dominant entity set.
Here, student is an entity and rollno is a primary key attribute. So, it forms a
strong entity set.
 Does not rely on any other entity for identification or existence.

Name Class
Marks
Rollno

Student

2. Weak entity type:


 An entity set that does not have a primary key is referred as a weak entity
set.
 It is represented by double rectangle.
 It contains a partial key represented by a dashed underline.
 The member of weak entity set is called as Sub-ordinate entity set.
 The relationship between one strong and a weak entity set is
represented by double diamond sign.

Paymentno
Loan

Loan
Loan Payment
Payment 4
3. Recursive entity type:
 It is also called as self-referential relationship entity type.
 It is an entity type with foreignkey referencing to same table or itself.
 It occurs in aunary relationship

Eid
Employee

Report
to
Supervisors Sub-ordinates

3. Explain about the classification of attributes?


Attributes:-
 Attributes are the properties that define the entity type.
 For example, Roll_No, Name, DOB, Age, Address, and Mobile_No are the
attributes that define entity type Student.
 In ER diagram, the attribute is represented by an oval.

Attribute

TypesofAttributes:-
Thedifferenttypesofattributesare:
 SingleValuedAttribute
 Multi-ValuedAttribute
 Simple/AtomicAttribute
 Compound/CompositeAttribute
 DerivedAttributes

5
 Key Attributes
 Non-key Attributes
1. Single valued Attributes:-
 An attribute that has a single value for a particular entity is known as
single valued attribute.
Ex:-Age of an employee entity.
2. Multi-Valued Attributes:-
 An attribute that can have multiple values for the same entity is known as
multi-valued attribute.
Ex:-Phone number can have multiple number of the same entity.
 It is represented with double oval.

3. Simple Attributes:-
 The attributes which can not be divided into smaller subparts are called as
simple (or) atomic attributes.
Ex:-The attributes like age, marital status cannot be sub-divided.
4. Compound Attributes:-
 The attributes which can be divided into smaller sub parts are called as
compound or composite attributes.
 It is represented with

Ex:-An employee name can be classified into firstname, middlename, last name.

Employeename

Firstname Last
middle

5. Derived Attributes:-
 The attributes that are derived from other attributes are called as derived
attributes.
Ex:-Age can be derived by the difference between current
date and date of birth.
 It is represented with-

6
6. Key Attributes: -
 It represents a primary key.
 It is the unique characteristic of the entity.
 It is represented by an oval with underlying lines.

7. Non-Key Attributes: -
 The attributes other than the primarykey in a table are called non-key
attributes.

4. Write about Relationship Degree?


Relationship Degree:
Relationship:-
 It represents an association among several entities.
Relationship type:-
 The way in which two(or)more entities are related is called as
relationship type.
 Relationship is represented with diamond shape.

Relationships based on degree:-


The number of participating entity types in a relationship is called Degree of
Relationship.
Types:-
The most common types of relationships based on degree are:
 Unary relationship
 Binary relationship
 Ternary relationship
 N-ary relationship
1. Unary relationship:-
 A relationship type of degree 1 is called unary relationship.
 When both the participants in the relationship belongs to the same

7
entity, then the relationship is called as Unary relationship.

2. Binary relationship:-
 A relationship type of degree 2 is called binary relationship.
 When two entities participated in the relationship, then the relationship is
called as Binary relationship.

Painter paints
Painting

3. Ternary relationship:-
 A relationship type of degree 3 is called ternary relationship.
 When three entities participated in the relationship , then the
relationship is called as Ternary relationship.

Employee Project
Assignment

Skills

4.N-aryrelationship:-
 A relationship type of degree n is called as N-ary relationship.
 When ‘N’ number of entities participated in the relationship , then the
Relationship is called as N-ary relationship.

8
E4

E1 R E2

E3

5. Explain about the classification of Relationship.


A. Relationship:
 It represents an association between several entities.
 A relationship works by matching data in key columns i.e., columns with
same name in both the tables.
 The relationship matches the primary key in one table and foreign key in
another table.
Types of Relationship:
The type of relationship that is created depends on “ How the related
columns are defined.”
There are four types of relationships in the table. They are:
 One-to-one relationship(1..1)
 One-to-many relationship(1..m)
 Many-to-many relationship(m..m)
 Many-to-one relationship(m..1)
One-to-one relationship:
 In a one-to-one relationship, each entity in one set is
associated with exactly one entity in another set, and vice
versa.
 Example: A Person can have only one Passport, and a
Passport belongs to only one Person.
 In this relationship , a row in table ‘A’ can have only one
matching row in
Table ‘B ’ and vice-versa.
 It is created, if both of the related columns are primary keys or unique
constraints.
 1 1
Student enroll Course

9
One-to-many relationship:
 In a one-to-many relationship, one entity in a set
is associated with multiple entities in another set,
but each entity in the second set is associated
with only one entity in the first set.
 Example: A Teacher can teach multiple Students,
but each Student is taught by only one Teacher.
 In this relationship, a row in table ‘A’ can have
many matching rows in table ‘B’, but a row in table
‘B ’can have only one match in grow in table ‘A’.

1 M
Manager Super Department
-

Many-to-one relationship:
 In a many-to-one relationship, multiple entities
in one set are associated with a single entity in
another set.
 Example: Many Employees work in one
Department, but each Department can have
many employees.
 In this relationship , many rows in table ‘A’ can
have only one matching
row in table ‘B’.
M 1
Students Attends Class

Many-to-many relationship:
 In a many-to-many relationship, entities in one set can
be associated with multiple entities in another set, and
vice versa.
 Example: Students can enroll in multiple Courses, and
each Course can have multiple Students.
 In this relationship, many number of rows in table ‘A’ can
have many

10
matching rows in table ‘B ’and vice-versa.

M M
Employee involve Project

6. Explain about EER model?


Enhanced/Extended Entity Relationship Model(EER):
Enhanced ER is a high-level data model that incorporates the extension to
the original ER model. It is a diagrammatic technique for displaying the following
concepts:
1. Sub-class and super class
2. Generalization and specialization
3. Union or category
4. Aggregation
Features of EER Model:
 It creates a design that can be more accurate to database schemas.
 It includes all modeling concepts of ER model.
 Diagrammatic technique helps for displaying EER schema.
 It includes the concepts of specialization and generalization.
 It is used to represent a collection of objects that is union of objects of different
entities. Types:
1. Sub-class and super class:
Sub-class and super class relationship lead the concept of inheritance.
 Super-Class: A generalized entity that defines common attributes and
relationships shared by multiple specialized entities (sub-classes). It acts as the
parent in an inheritance hierarchy.
 Sub-Class: A specialized entity that inherits the attributes and relationships of
the super-class but may also define additional attributes or relationships unique
to itself.
shape

square circle rectangle

11
2. Generalization and specialization:

Generalization:
 It is the process of extracting shared characteristics from two or more classes and
combining them into generalized super class.
 It is a bottom-up approach , in which two or more lower-level entities are
combined to form a higher-level entity.
 It defines a general entity type from a set of specialized entity types.
 In this , super class is called as general entity and sub-classes are special entities.
 It minimizes the difference between entities by identifying the common attributes
or features.

 These two entities have two common attributes: Name and Address, we can
make a generalized entity with these common attributes. Lets have a look at the ER
model after generalization.
The ER diagram after generalization:
We have created a new generalized entity Person and this entity has the common
attributes of both the entities. As you can see in the following ER diagram that after
the generalization process the entities Student and Teacher only has the specialized
attributes Grade and Salary respectively and their common attributes (Name &
Address) are now associated with a new entity Person which is in the relationship with
both the entities (Student & Teacher).

12
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.
 The idea behind Specialization is to find the subsets of entities that have few
distinguish attributes. For example – Consider an entity employee which can be
further classified as sub-entities Technician, Engineer & Accountant because
these sub entities have some distinguish attributes.
Specialization Example

3. Union or Category:
 It represents a single sub-class relationship with more than one super class.

13
 It can be a total or partial participation.
 A category member must exist atleast one of its super classes.

car bike bicycle

Registeredvehicle

4. 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.
Aggregration Example

 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”.
6. Explain about constraints on generalization and specialization?
14
A. Constraints on Generalization:
Generalization: It is the process of extracting the shared characteristics from
two or more subclasses, then combining them into the generalized super class.
Specialization: It refers to creating new sub-classes from existing class with
unique characteristics.
Constraints: The different types of constraints on generalization and
specialization are:
1. Predicate defined or condition defined constraints
2. Attribute defined constraints
3. Disjoint and overlapping
4. Completeness constraints
5. Specialization hierarchies and lattice.

1. Predicate defined constraints:


 It refers to placing the condition on a value of attribute which identifies
sub-classes.
 It specifies that , which members of sub-class can satisfy the
predicate.
 Ex: Secretary sub-class by defining the predicate job type= secretary
2.Attribute defined constraints:
 It specifies that, all sub-classes having membership condition on same
attribute of super-class.
Ex:Jobtype
3. Disjoint and overlapping constraints:
 It specifies that sub-classes of specialization must be disjoined i.e.,an
entity belongs to at most one sub-class only.
 If sub-classes are not disjoint, then set of entities may overlap.
Disjoint Overlap

Employee Person

Developer Tester Employee Student

4. Completeness constraints:
 It specifies that, whether each entity super-type occurrence must also be a
member of at least one sub-type.

15
 There are two types of completeness constraints
 Total completeness
 Partial completeness
Total completeness:
 It means that, every super type occurrence is member of subtype.
Partial completeness:
 It means that not every super type occurrence is member of sub type.
5. Specialization hierarchies and lattice:
The sub-class itself can have further sub-classes specified on it, forming
hierarchy or lattice of specialization.
A specialization hierarchy provides the means to:
I. Support attribute inheritance
II. Define disjoint/overlapping and completeness/partial constraints.

7. Write about Multiple inheritance in EER model?


Inheritance:-
 Inheritance is an important feature of generalization and specialization.
 Inheritance is represented with ISA relationship.
 ISA relationship is represented with

There are several forms of inheritance.


1. Single inheritance
2. Multiple inheritance
3. Repeated inheritance
4. Selective inheritance

1. Single Inheritance:-

It refers that, the subclass inherits the attributes from only one super class.

person

employee student

2. Multiple Inheritance:-

It refers that, the subclass inherits the attributes from more than one super class.
16
bonus M_id bonus S_id

manager Salesstaff

Sm-id

Salesmanager

The multiple inheritance is very problematic, the problem arises when the super
classes contain the same attribute.
It can be handled in following ways.
1. It includes attributes and use the name of the super class as qualifier.
For example, the super classes manager and the sales staff have the
same attribute bonus then the subclass sales manager can inherit
bonus has either manager. bonus(or)sales staff. bonus.
2. Use single inheritance to avoid the problem.

Ex:-sales manager sale staff manager


(or)
Sales manager manager sale staff

3. Repeated Inheritance:-
It is a special case of multiple inheritance in which the super classes inherit from
a common super class.
staff

manager Salesstaff

Salesmanager

4. Selective inheritance:-It allows the subclass to inherit a limited no.of attributes


from subclass.

17
8. Write about Aggregation and Composition?
Aggregation:(Refer aggregation in EER model)
Composition: It is a special case of aggregation. A restricted aggregation is
called as composition.
→When an object contains another object, if the contained object cannot
exist without the existence of container object, then it is called as
composition.
Ex: If a class contains student, a student cannot exist with out a class because
there exists composition between class and student.

Difference between Aggregation and composition:

Key Composition Aggregation

Composition is a way to wrap simple objects or data Aggregation differs from ordinary composition in that it
Basic
types into a single unit. does not imply ownership.

In Aggregation, parent Has-A relationship with child


Relationship In composition, parent entity owns child entity.
entity.

Tells about Composition tells about a mixture. Aggregation tells about a collection.

UML
It is denoted by a filled diamond. It is denoted by an empty diamond.
Notation

Life cycle Child doesn't have their own life time. Child can have their own life time.

Association It is a strong association. It is a weak association.

9. Write about advantages and disadvantages of ER modeling.


ER model:
 It was introduced by Peterchen in 1976.
 It describes the structure of Database with the help of diagrams , which
is known as ERD (Entity Relationship Diagrams).
 It is a blue-print or design of Database that can later be implemented as
Database.

18
Advantages:
Following are the advantages of ER model.
1. Straight forward relation representation:
Having designed in ER diagram for database application, the relational
representation of the database model becomes relatively straight forward.

2. Conceptually it is very simple:


Making the ER Diagram is very easy process.
3. Easy conversion from ER to other data models:
The conversion from ER diagram to any other data model can be easily
accomplished.
4. Better Visual Representation:
An ER model gives graphical and diagrammatical representation of various
entities, attributes and relationship between entities.
5. ER diagram constitute a very useful frame work for creating and manipulating
database.
6. It is an effective communication tool.
7. ER diagrams are very easy to translate into relational tables which can be used
to quickly build databases.
8. It is very efficient.
9. It is highly integrated with relational model.
10. Easy conversion to any data model.
Disadvantages:
Following are the disadvantages of ER model:
1. No industry standard for notation:
There is no industries standard notation for developing in ER diagram.
2. Popular for high level design:
The ER data model is especially popular for high level.
3. Only for relational data:
It is used to show the relationships .It shows only the relational structure.
4. Not for unstructured data:
It is only used for structured data.
5. Its is difficult to exist with different architectures.
6. There are limited constraints and specifications in the ER diagram.
7. Limited relationships.

19
11. Explain about the conversion of ER diagrams to tables
A. Reducing ER diagrams to tables:
ER Diagrams gives us the good knowledge about the requirement and
the mapping of the entities in it. So, we can easily convert them as tables and
columns.

Rule-01: For Strong Entity Set with Only Simple Attributes


A strong entity set with only simple attributes will require only one table in relational
model. Attributes of the table will be the attributes of the entity set. The primary key
of the table will be the key attribute of the entity set.

Example

Rule-02: For Strong Entity Set with Composite Attributes


A strong entity set with number of composite attributes will require only one table in
relational model. While conversion, simple attributes of the composite attributes are taken
into account and not the composite attribute itself.
Example

20
Rule-03: For Strong Entity Set with Multi Valued Attributes
A strong entity set with any number of multi valued attributes will require two tables in
relational model. One table will contain all the simple attributes with the primary key.
Other table will contain the primary key and all the multi valued attributes.
Example

Rule-04: Translating Relationship Set into a Table


A relationship set will require one table in the relational model.
Attributes of the table are- Primary key attributes of the participating entity set
Its own descriptive attributes if any.
Set of non-descriptive attributes will be the primary key.
Example

21
Schema: Works in (Emp_no, Dept_id, since)
Rule-05: For Binary Relationships with Cardinality Ratios
A Binary Relationships with Cardinality Ratios are mentioned having Four different cases
with their relationship. These are mentioned below. They are....
Case-01: Binary relationship with cardinality ratio min
Case-02: Binary relationship with cardinality ratio 1: n
Case-03: Binary relationship with cardinality ratio m:1
Case-04: Binary relationship with cardinality ratio 1:1

Case-01: For Binary Relationship with Cardinality Ratio m: n

22
23
24
IIIBSC-DBMS

 UsingER-Diagrams,onecaneasilycreaterelational datamodel. Ex:


Consider an ER-Diagram of a college

 The basic rules for converting ER Diagrams into tables are:

12. Write about IS-A relationship and Attribute Inheritance


A. Inheritance:
 Inheritance is an important feature of generalization and specialization.
 It allows lower-level entities to inherit the attributes of higher-level

25
IIIBSC-DBMS
attributes.
 Inheritance is represented with ISA relationship.
 ISA relationship is represented with

IS-A

Attribute inheritance:
 A crucial property of the higher and lower-level entities which is created by
specialization and generalization is attribute inheritance.
 The attributes of the higher-level entity sets are said to be inherited by the
lower-level entity sets.

Here, the attributes of a person class such as name, gender, city can be inherited
by lower-level entity such as student and teacher.
 Attribute inheritance applied through all tiers of lower-level entity sets.
 If the ER model was arrived at by specialization and generalization then
the outcome is
→ A higher-level entity set with attributes and relationships that
apply to all of its lower-level entity sets.
→ A lower-level entity sets with distinctive features that applied
with only within a particular lower-level entity set.

13. Write about entity clustering.


Entity Clustering
 EER diagrams are difficult to read when there are many entities and relationships.
 One possible solution is to group entities and relationships in to entity clusters.

26
IIIBSC-DBMS
 An entity cluster is a “virtual” entity type used to represent multiple entities and
Relationships in the ERD.
 An entity cluster is formed by combining multiple interrelated entities into a
single abstract entity object.
 Entity cluster behaves like an entity type ;hence entity clusters and entity types
can be further grouped to form a higher-level entity cluster.

In the above EER model, management is responsible to appoint doctors of different


categories, and also, they establish different buildings. Doctors treat patients who are
classified into inpatient &out patients. In the above diagram, there are so many entities.
To reduce that complexity, we use entity clusters to doctor & patients.

27

You might also like