DBMS_Unit -II
DBMS_Unit -II
An ER diagram Is used for creating a systematic study of the data requirements and
then making a proper database. It is considered to be one of the best practices before
implementing an actual database.
Entity set
It is a collection of entities of the same type which share similar properties. For example, a
group of students in a college and students are an entity set.
Entity is characterised into two types as follows:
a. Strong entity set: The entity types which consist of key attributes or if there are enough
attributes for forming a primary key attribute are called a strong entity set. It is represented
by a single rectangle.
b. Weak entity set: An entity does not have a primary key attribute and depends on
another strong entity via foreign key attribute. It is represented by a double
rectangle.
2. Attributes
These are the data characteristics of entities or data elements and data fields.
Types of attributes
The types of attributes in the Entity Relationship (ER) model are as follows:
1. Single value attribute − these attributes contain a single value. For example, age,
salary etc.
2. Key Attributes- The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented by an ellipse with
the text underlined.
3. Multivalued attribute − they contain more than one value of a single entity. For
example, phone numbers, Email_Ids, etc.
4. Composite attribute − the attributes which can be further divided. For example,
Name
consists of First name, Middle name, last name
5. Derived attribute − the attribute that can be derived from other attributes. For
example, age can be derived based on DoB.
3. Relationships
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.
Degree of Relationship: A relationship where a number of different entities set participate is
called a degree of a relationship.
1. Unary Relationship: A unary relationship exists when both the participating entity
type are the same. When such a relationship is present we say that the degree of
relationship is 1.
2. Binary Relationship: A binary relationship exists when exactly two entity type
participates. When such a relationship is present we say that the degree is 2. This is
the most common degree of relationship. It is easy to deal with such relationship as
these can be easily converted into relational tables.
For example, we have two entity type ‘Customer’ and ‘Account’ where each
‘Customer’ has an ‘Account’ which stores the account details of the ‘Customer’.
Since we have two entity types participating we call it a binary relationship. Also, one
‘Customer’ can have many ‘Account’ but each ‘Account’ should belong to only one
‘Customer’. We can say that it is a one-to-many binary relationship.
3. Ternary Relationship: A ternary relationship exists when exactly three entity type
participates. When such a relationship is present we say that the degree is 3. As the
number of entity increases in the relationship, it becomes complex to convert them
into relational tables.
For example, we have three entity type ‘Employee’, ‘Department’ and ‘Location’.
The relationship between these entities are defined as an employee works in a
department,
an employee works at a particular location. So, we can see we have three entities
participating in a relationship so it is a ternary relationship. The degree of this relation
is 3.
4. n-ary Relationship: An N-ary relationship exists when ‘n’ number of entities are
participating. So, any number of entities can participate in a relationship. There is no
limitation to the maximum number of entities that can participate.
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.
It is most useful in describing the relationship sets that involve more than two entity
sets.
For binary relationship set R on an entity set A and B, there are four possible mapping
cardinalities.
a. One-to-One (1:1)
b. One-to-Many (1:M)
c. Many-to-One (M:1)
d. Many-to-Many (M:M)
a. 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.
For example: A female can marry to one male, and a male can marry to one female.
b. 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.
For example, Scientist can invent many inventions, but the invention is done by the only
specific scientist.
c. 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.
For example, Student enrolls for only one course, but a course can have many students.
d. 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.
For example, Employee can assign by many projects and project can have many employees.
A given ER model can be converted into Relational model. A Relational model includes
Relations, Tuples, Attributes, Keys, and Foreign keys.
Employee
Works_On
Projects
Super class shape has sub groups: Triangle, Square and Circle.
Sub classes are the group of entities with some unique attributes. Subclass inherits the
properties and attributes from super class.
For example, Faculty and Student entities can be generalized and create a higher level entity
Person.
Specialization is a top-down approach, and it is opposite to Generalization. In
specialization, one higher level entity can be broken down into two lower level
entities.
Specialization is used to identify the subset of an entity set that shares some
distinguishing characteristics.
Normally, the superclass is defined first, the subclass and its related attributes are
defined next, and relationship set are then added.
For example, in the bellow diagram we have 3 sub entities Car, Truck and Motorcycle. The
three entities can be generalized into one super class named as Vehicle (Generalization).
Relationship of one super or sub class with more than one super class.
Aggregation
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.
For example: Centre entity offers the Course entity act as a single entity in the relationship
which is in a relationship with another entity visitor. In the real world, if a visitor visits a
coaching Centre then he will never enquiry about the Course only or just about the Centre
instead he will ask the enquiry about both.