DBMS UNIT 2 New
DBMS UNIT 2 New
1
Basic building blocks of ER Model:
The basic building blocks of ER-Model are
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
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
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
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
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.
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
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
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.
Registeredvehicle
4. Aggregation:
Employee Person
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.
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.
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
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.
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.
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.
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.
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.
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
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
22
23
24
IIIBSC-DBMS
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.
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.
27