0% found this document useful (0 votes)
62 views

Unit 2 DBMS-1

The document discusses key concepts in Entity-Relationship (E-R) modeling including entities, entity sets, attributes, relationships, keys, and cardinalities. The E-R model represents real-world objects and their interactions through entities, entity sets, attributes, and relationships. Entities have attributes and are grouped into entity sets. Relationships associate entities and have cardinalities like one-to-one, one-to-many, etc. Keys like primary keys and foreign keys are used to uniquely identify entities and define relationships between entities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Unit 2 DBMS-1

The document discusses key concepts in Entity-Relationship (E-R) modeling including entities, entity sets, attributes, relationships, keys, and cardinalities. The E-R model represents real-world objects and their interactions through entities, entity sets, attributes, and relationships. Entities have attributes and are grouped into entity sets. Relationships associate entities and have cardinalities like one-to-one, one-to-many, etc. Keys like primary keys and foreign keys are used to uniquely identify entities and define relationships between entities.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 26

UNIT-2

Entity-Relationship (E-R) Modeling or E R Diagram:-


E R model is based on the perception of real world objects that consists of
collection of objects called entities. E R Modeling was developed to facilitate
database design by allowing specification of an enterprise schema that represents
the overall logical structure of a database. The E-R model is very useful in
mapping the meanings and interactions of real-world enterprises onto a conceptual
schema. The E-R data model employs three basic concepts: entity sets, relationship
sets, and attributes. It was developed by Peter Cehn in 1976.

Entity
An entity is an object that exists and is distinguishable from other objects.
Anything about which we store information is called an entity.
An entity has a set of properties, and the values for some set of properties may
uniquely identify an entity. It includes all those things about which data is
collected. An entity may be tangible object such as student, place etc. It may be
non-tangible object such as event, job title or customer account. For instance, a
person may have a person id property whose value uniquely identifies that person.

Entities are represented by means of rectangles. Rectangles are named with the
entity set they represent.
Entity Set
It is a set of entities of the same type that share the same properties, or attributes.
An entity set is a collection of similar types of entities. An entity set may contain
entities with attribute sharing similar values. For example, a Students set may
contain all the students of a college; set of persons who are customers at given
bank.
Attributes
Entities are represented by means of their properties, called attributes. All
attributes have values. Attributes are units that describe the properties of entities.
For example, a student entity may have name, class, and age as attributes.
There exists a domain or range of values that can be assigned to attributes. For
example, a student's name cannot be a numeric value. It has to be alphabetic. A
student's age cannot be negative, etc.

Types of Attribute
 Simple Attribute: Simple attributes are atomic values, which cannot be
divided further. For example, a student's phone number is an atomic value of
10 digits.
 Composite Attribute: Composite attribute which can be divided into sub
parts. Composite attributes are made of more than one simple attribute. For
example, a student's complete name may have first_name and last_name.
 Derived Attribute: The value for this type of attribute can be derived from
the values of other related attributes or entities. For example, age can be
derived from birth date and current date.
 Thus, age is derived attribute and birth date is base attribute or stored
attribute.
 Stored Attribute: The stored attribute are such attribute which are already
stored in the database. For example birth date.

Derived Attribute
 Single-Value Attribute: Single-value attributes contain single value. For
example − Age, Roll_no
 Multi-Valued Attribute: Multi-value attributes may contain more than one
value. For example, a person can have more than zero, one or several mobile
number, email address, etc.
Multi valued attributes are depicted by double ellipse.
Multi valued Attribute
Keys:
It is used to uniquely identify any record or row of data from the table. It is also
used to establish and identify relationships between tables.
For example: In Student table, ID is used as a key because it is unique for each
student.
Types of Keys:-
Database supports the following types of keys.
 Primary Key
 Super Key
 Candidate Key
 Alternate Key
 Composite Key
 Foreign Key
Now we take one table for better understanding of the key that is
“Branch Info”
Primary Key

Primary key is a set of one or more fields (columns) of a table that uniquely
identify a record in table. It cannot contain Null value and duplicate value. A table
can have only one primary key and one candidate key can select as a primary key.
The primary key should be chosen such that its attributes are never or rarely
changed, for example, Roll_no, Emp_id are primary keys.

Rules for defining Primary key:-


 Two rows can't have the same primary key value
 It must for every row to have a primary key value.
 The primary key field cannot be null.
 The value in a primary key column can never be modified or updated if any
foreign key refers to that primary key.

Example of Primary Key:-


Primary Key in Branch_Info table:
1. Branch_Id

Super Key:-

Super key is a set of one or more than one keys that can be used to uniquely
identify the record in table. A Super key for an entity is a set of one or more
attributes whose combined value uniquely identifies the entity in the entity set.
Super Key is superset of candidate key. If anyone adds additional attributes to
primary key the resulting would still identify the entity.

Example:-
Super Keys in Branch_Info Table.
1. Branch_Id
2. Branch_Name
3. Branch_Code
4. { Branch_Id, Branch_Code }
5. { Branch_Name , Branch_Code }
Candidate Key

A Candidate key is an attribute or set of attributes that uniquely identifies a record


in a table. Among the set of candidate, one candidate key is chosen as Primary
Key. So a table can have multiple candidate keys but each table can have
maximum one primary key. For Example Roll_No & Student_name are candidate
keys and Roll_No is also candidate key.

Example of Candidate key:-

Possible Candidate Keys in Branch_Info table.

1. Branch_Id
2. Branch_id, Branch_Name
3. Branch_Code

Alternate Key:-

Alternate keys are candidate keys that are not selected as primary key. Alternate
key is also called “Secondary Key”. For Example Roll_No is primary key and rest
Student_Name & Address are alternate keys.

Example:

Alternate Key in Branch_Info table:

1. Branch_Code

Composite Key:-

Composite key is a combination of more than one attributes that can be used to
uniquely identity each record. It is also known as “Compound” key. A composite
key may be a candidate or primary key.
Example:

Composite Key in Branch_Info table.


1. { Branch_Name, Branch_Code}

Foreign Keys:
Foreign key is used to generate the relationship between the tables. Foreign Key is
a field in database table that is Primary key in another table. A foreign key can
accept null and duplicate value. Foreign keys are the column of the table which is
used to point to the primary key of another table.

Example:

In a company, every employee works in a specific department, and employee and


department are two different entities. So we can't store the information of the
department in the employee table. That's why we link these two tables through the
primary key of one table.

o We add the primary key of the DEPARTMENT table, Department_Id as a


new attribute in the EMPLOYEE table.
o Now in the EMPLOYEE table, Department_Id is the foreign key, and
both the tables are related.

Primary Key

Foreign Key

Relationship
The association among two or more entities is called a relationship. For example,
an employee works_at a department, a student enrolls in a course. Here,
Works_at and Enrolls are called relationship. It is represented by diamond
symbol.
Mapping cardinalities express the number of entities to which another entity can
be associated via a relationship set.It may be one to one (1:1), one-to-many (1:
M), many-to-many (M: M), many-to-one (M: 1).
Relationship Set
A relationship set is a set of relationships of the same type. Like entities, a
relationship too can have attributes. These attributes are called descriptive
attributes.
Types of Relationship or Mapping Cardinalities:-
 One-to-One (1:1):- One entity E1 is related with almost one entity E2 and
E2 is related to E1.
 One-to-Many (1: M):- An entity in A is associated with any number (zero
or more) of entities in B. An entity in B, however, can be associated with at
most one entity in A.
 Many-to-one. An entity in A is associated with at most one entity in B. An
entity in B, however, can be associated with any number (zero or more) of
entities in A.
 Many-to-many. An entity in A is associated with any number (zero or
more) of entities in B, and an entity in B is associated with any number
(zero or more) of entities in A.

Degree of Relationship: It is the number of entities associated in relationship.


 Unary or Recursive Relationship: - It is the relationship type is between
entities in a single entity. For Example:-
 Binary Relationship: - It is relationship between two entities.

 Ternary Relationship:-It is relationship between three entities.

What is Role?
Each entity in a relationship plays a particular role. The role name specified the
role that participating entity plays in a relationship and explain what relationship
means. A relationship between two entities of similar entity type is called
a recursive relationship. Here the same entity type participates more than
once in a relationship type with a different role for each instance.
 Entity sets of a relationship need not be distinct
 The labels “manager” and “worker” are called roles; they specify how
employee entities interact via the works_for relationship set.
 Roles are indicated in E-R diagrams by labeling the lines that connect
diamonds to rectangles.
 Role labels are optional, and are used to clarify semantics of the relationship
Integrity Constraints:-
 Integrity constraints are a set of rules. It is used to maintain the quality of
information.
 Integrity constraints ensure that the data insertion, updating, and other
processes have to be performed in such a way that data integrity is not
affected.
 Thus, integrity constraint is used to guard against accidental damage to the
database.

Types of Integrity Constraint (BCA 2017)

1. Domain constraints

 Domain constraints can be defined as the definition of a valid set of values


for an attribute.
 The data type of domain includes string, character, integer, time, date,
currency, etc. The value of the attribute must be available in the
corresponding domain.

Example:
2. Entity integrity constraints (BCA 2017)
 The entity integrity constraint states that primary key value can't be null.
 This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those
rows.
 A table can contain a null value other than the primary key field.

Example:

3. Referential Integrity Constraints (BCA 2017)


o A referential integrity constraint is specified between two tables.
o In the Referential integrity constraints, if a foreign key in Table 1 refers to
the Primary Key of Table 2, then every value of the Foreign Key in Table 1
must be null or be available in Table 2.

Example:
Key constraints

 Keys are the entity set that is used to identify an entity within its entity set
uniquely.
 An entity set can have multiple keys, but out of which one key will be the
primary key. A primary key can contain a unique and null value in the
relational table.

Structural Constraints
Relationship types have certain constraints that limit the possible combination of
entities that may participate in relationship.

Types of structural constraints


1. Cardinality Ratio or Mapping Constraints: The cardinality specifies the
maximum number of relationship instances that an entity can participate in.
Cardinality is the term used in database relations to denote the occurrences of
data on either side of the relation.

Types of cardinality ratio


a) One-to-One: An E1 entity may be associated with at most one E2 entity and
similarly an E2 entity may be associated with at most one E1 entity.
b) One-to-Many: An E1 entity may be associated with many E2 entities
whereas an E2 entity may be associated with at most one E1 entity.

c) Many-to-One: An E1 entity may be associated with at most one E2 entity


whereas an E2 entity may be associated with many entities.
d) Many-to-Many: Many E1 entities may be associated with a single E2 entity
and a single E1 entity may be associated with many E2 entities.
2. Participation Constraints: The participation constraint specifies whether the
existence of an entity depends on its being related to another entity via the
relationship type.
Participation constraints deal with whether participation of individual entities in
a relationship between entity types is mandatory or optional.
a) Total Participation - If an entity can exist, only if it participates in at least
one relationship instance, then that is called total participation, meaning
that every entity in one set must be related to at least one entity in a
designated entity set. It is also sometimes called an existence
dependency.
b) Partial Participation- If only a part of the set of entities participate in a
relationship, then it is called partial participation. Partial Participation is
represented by a single line.

Strong Entity Set: A strong entity is one that has a complete identifier whose
values may be used to identify its instances uniquely. An entity set that has a
primary key is termed a strong entity set.
For example- The employee has an identifier Employee_Id. The attribute name is
not its full identifier because there are two employees which have the same name.
Weak Entity Set: An entity set that does not have sufficient attributes to form a
primary key is termed a weak entity set. Some entity types may not have any key
attributes of their own; these are called weak entity types. A weak entity is
dependent on a strong entity type, i.e. it can not be identified without the existence
of the associated strong entity. Every weak entity must be associated with an
identifying entity; that is, the weak entity set is said to be existence dependent on
the identifying entity set. The identifying entity set is said to own the weak entity
set that it identifies. The relationship associating the weak entity set with the
identifying entity set is called the identifying relationship
The weak entity set section depends on the strong entity set course
Through the relationship set sec course.

E-R diagram with a weak entity set.

Another Example of Strong and Weak Entity Set


Difference between strong and weak entity set:-
Strong entity set Weak entity set
It has its own primary key. It does not have sufficient attributes to
form a primary key on its own.
It is represented by a rectangle. It is represented by a double rectangle.
The member of strong entity set is called The member of weak entity set is called
as dominant entity. as subordinate entity.
The line connection strong entity set with The line connecting weak entity set with
the relationship is single. the identifying relationship is double.
The relationship between two strong The relationship between one strong and a
entity set is represented by a diamond weak entity set is represented by a double
symbol. diamond sign. It is known as identifying
relationship.
The primary key is one of its attribute The primary key of weak entity set is a
which uniquely identifies its member. combination of partial key and primary
key of the strong entity set.
Total participation in the relationship may Total participation in the identifying
or may not exist. relationship always exists.

Following are the components of ER Diagram,


Enhanced Entity relationship (EER) & Object Modeling:-

The EER Model includes all modeling concept of ER Model and the concepts of
specialization, generalization, higher- and lower-level entity sets, attribute
inheritance, and aggregation. EER is a high-level data model that incorporates the
extensions to the ER model. Enhanced entity-relationship models, also known as
extended entity-relationship models. Enhanced ER Model is high-level models that
represent the requirements and complexities of complex databases.
Features of EER Model:-
 EER creates a design more accurate to database schemas.
 It reflects the data properties and constraints more precisely.
 It includes all modeling concepts of the ER model.
 Diagrammatic technique helps for displaying the EER schema.
 It includes the concept of specialization and generalization.
 It is used to represent a collection of objects that is union of objects of
different of different entity types.

Super Class
 Super class is an entity type that has a relationship with one or more
subtypes.
 The general entity (super class) can be sub divide into several entities
(subclass).
For example: Shape super class is having sub groups as Square, Circle, and
Triangle.
 Higher- and lower-level entity sets also may be designated by the terms
super class and subclass, respectively.
2. Sub Class
 Sub class is a group of entities with unique attributes. It is member of super
class.
 Sub class inherits properties and attributes from its super class.
For example: Square, Circle, Triangle are the sub class of Shape super
class.
Generalization
 Generalization is like a bottom-up approach in which two or more entities of
lower level combine to form a higher level entity if they have some
attributes in common.
 In generalization, an entity of a higher level can also combine with the
entities of the lower level to form a further higher level entity.
 Generalization is more like subclass and super class system, but the only
difference is the approach. Generalization uses the bottom-up approach.
 In generalization, entities are combined to form a more generalized entity,
i.e., subclasses are combined to make a super class.
 Generalization is a simple inversion of specialization.
 For example, Employee and Student entities can be generalized and create a
higher level entity Person.

I p
e De
mn r
p as
l mo s
e
o n t
ya u
d
d Generalization
e d tot_credits
salary
er e
e n
s
s t

instructor secretary
rank hours_per_week

Generalization

Specialization
 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 super class is defined first, the subclass and its related
attributes are defined next, and relationship set are then added.
 The process of designating sub groupings within an entity set is called
specialization.

For example: person entity can be specialized as employee or customer.

Specialization

Attribute Inheritance
Inheritance is an important feature of Generalization and Specialization. It
allows lower-level entities to inherit the attributes of higher-level entities.

A lower-level entity set inherits all the attributes and relationship participation of
the higher-level entity set to which it is linked.
A crucial property of the higher- and lower-level entities 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.
For example, the attributes of a Person class such as name, age, and gender can be
inherited by lower-level entities such as Student or Teacher.

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. Aggregation is an abstraction through which relationships are treated
as higher-level entities.

For example: We create a binary relation between works_on and manager.


Employee works in branch and employee works on job is treated as a single entity
and which relates to manager entity.
SOLVED UNIVERSITY QUESTION OF E R DIAGRAM:-
Q1. 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.
Solution:-

ER Diagram of CAR Insurance Company


Q2. Design an E-R diagram for keeping track of exploits of your favorite sports
team. You should store the matches played, the scores in each match, the players in
each match, and individual player statistics for each match. Summary statistics
should be modeled as derived attributes.
Answer:

Q3 A university registrar’s office maintains data about the following entities: (a)
courses, including number, title, credits, syllabus, and prerequisites; (b) course
offerings, including course number, year, semester, section number, instructor(s),
timings, and classroom; (c) students, including student-id, name, and program;
and (d) instructors, including identification number, name, department, and title.
Further, the enrollment of students in courses and grades awarded to students in
each course they are enrolled for must be appropriately modeled. Construct an E-
R diagram for the registrar’s office. Document all assumptions that you make
about the mapping constraints.
Solution:-

Q4. Consider a database used to record the marks that students get in different
exams of different course offerings.
a. Construct an E-R diagram that models exams as entities, and uses a ternary
relationship, for the above database.
b. Construct an alternative E-R diagram that uses only a binary relationship
between students and course-offerings. Make sure that only one relationship exists
between a particular student and course-offering pair, yet you can represent the
marks that a student gets in different exams of a course offering.

Ans 4A)
Ans: 4B)

Q5. Construct an E-R diagram for a hospital with a set of patients and a set of
medical doctors. Associate with each patient a log of the various tests and
examinations conducted.
Q6. Construct E R Diagram for ONLINE Book Store

Q7.Construct ER digram for bank database.


Q8.Construct ER digram for Library management database.

Q9. Construct an E R Diagram for Exam Scheduling.


Consider a university database for the scheduling of classrooms for final exams. This
database could be modeled as the single entity set exam, with attributes course-name, section-
number, room-number, and time. Alternatively, one or more additional entity sets could be
defined, along with relationship sets to replace some of the attributes of the exam entity set, as
• Course with attributes name, department, and c-number
• Section with attributes s-number and enrollment, and dependent as a weak entity set on course
• room with attributes r-number, capacity, and building
a. Show an E-R diagram illustrating the use of all three additional entity sets listed.
b. Explain what application characteristics would influence a decision to include or not to
include each of the additional entity sets.
Ans 9 A)

9 B) The additional entity sets are useful if we wish to store their attributes as part of the
database. For the course entity set, we have chosen to include three attributes. If only the
primary key (c-number) were included, and if courses have only one section, then it would be
appropriate to replace the course (and section) entity sets by an attribute (c-number) of exam.
The reason it is undesirable to have multiple attributes of course as attributes of exam is that it
would then be difficult to maintain data on the courses, particularly if a course has no exam or
several exams. Similar remarks apply to the room entity set.

You might also like