Unit 2 Data Modeling Using the Entity-Relational Model bitinfoNepal
Unit 2 Data Modeling Using the Entity-Relational Model bitinfoNepal
Specialization - is a top-down approach in which a higher-level entity is divided into multiple specialized
lower-level entities. In addition to sharing the attributes of the higher-level entity, these lower-level
entities have specific attributes of their own. Specialization is usually used to find subsets of an entity that
has a few different or additional attributes.
The following enhanced entity relationship diagram expresses the entities in a hierarchical database to
demonstrate specialization:
Generalization - is a bottom-up approach in which multiple lower-level entities are combined to form a
single higher-level entity. Generalization is usually used to find common attributes among entities to form
a generalized entity. It can also be thought of as the opposite of specialization.
The following enhanced entity relationship diagram expresses entities in a hierarchical database to
demonstrate generalization:
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
When you are designing attributes for your entities, you will sometimes find that an attribute does not
have a value for every instance of the entity. For example, you might want an attribute for a person's
middle name, but you can't require a value because some people have no middle name. For these
occasions, you can define the attribute so that it can contain null values.
A null value is a special indicator that represents the absence of a value. The value can be absent because
it is unknown, not yet supplied, or nonexistent. The DBMS treats the null value as an actual value, not as
a zero value, a blank, or an empty string.
Just as some attributes should be allowed to contain null values, other attributes should not contain null
values. Example: For the EMPLOYEE entity, you might not want to allow the attribute
EMPLOYEE_LAST_NAME to contain a null value.
Weak Entity - The entity sets which do not have sufficient attributes to form a primary key are known as
weak entity sets and the entity sets which have a primary key are known as strong entity sets.
As the weak entities do not have any primary key, they cannot be identified on their own, so they depend
on some other entity (known as owner entity). The weak entities have total participation constraint
(existence dependency) in its identifying relationship with owner identity. Weak entity types have partial
keys. Partial Keys are set of attributes with the help of which the tuples of the weak entities can be
distinguished and identified.
Weak entities are represented with double rectangular box in the ER Diagram and the identifying
relationships are represented with double diamond.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
Strong Entity (Owner Entity Type) - A strong entity is not dependent on any other entity in the schema.
A strong entity will always have a primary key. Strong entities are represented by a single rectangle. The
relationship of two strong entities is represented by a single diamond.
Identifying Relationship - The relationship that relates the weak entity type to an owner entity type is
known as identifying relationship.
4. Construct an ERD to record the marks that students get in different exams of different course
offerings.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
5. Draw an ER diagram for database showing Bank. Each Bank can have multiple branches, and each
branch can have multiple accounts and loans.
Simple attribute - An attribute that cannot be further subdivided into components is a simple
attribute. Example: The roll number of a student, the id number of an employee.
Single-valued attribute - The attribute which takes up only a single value for each entity instance is a
single-valued attribute. Example: The age of a student.
Multi-valued attribute - The attribute which takes up more than a single value for each entity instance
is a multi-valued attribute. Example: Phone number of a student: Landline and mobile.
7. Draw an ER diagram for database showing hospital system. The Hospital maintains data about
affiliated Hospitals, type of treatments facilities given at each hospital and patients.
8. Write the difference among an entity, an entity type, and an entity set.
An entity is a real-world thing which can be distinctly identified like a person, place or a concept. It is
an object which is distinguishable from others.
The entity type is a collection of the entity having similar attributes. In the below Student table example,
we have each row as an entity and they are having common attributes i.e each row has its own value
for attributes Roll_no, Age, Student_name and Mobile_no. So, we can define the above STUDENT table
as an entity type because it is a collection of entities having the same attributes.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
Entity Set is a collection of entities of the same entity type. In the above example of STUDENT entity
type, a collection of entities from the Student entity type would form an entity set.
-One-to-One Relationship: Such a relationship exists when each record of one table is related to only
one record of the other table. Eg: If there are two entities ‘Person’ (Id, Name, Age, Address)and
‘Passport’(Passport_id, Passport_no). So, each person can have only one passport and each passport
belongs to only one person.
- One-to-Many or Many-to-One Relationship: Such a relationship exists when each record of one table
can be related to one or more than one record of the other table. This relationship is the most common
relationship found. A one-to-many relationship can also be said as a many-to-one relationship
depending upon the way we view it. Eg: If there are two entity type ‘Customer’ and ‘Account’ then each
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
‘Customer’ can have more than one ‘Account’ but each ‘Account’ is held by only one ‘Customer’. In this
example, we can say that each Customer is associated with many Account. So, it is a one-to-many
relationship. But, if we see it the other way i.e many Account is associated with one Customer then we
can say that it is a many-to-one relationship.
- Many-to-Many Relationship: Such a relationship exists when each record of the first table can be
related to one or more than one record of the second table and a single record of the second table can
be related to one or more than one record of the first table. A many-to-many relationship can be seen
as a two one-to-many relationship which is linked by a 'linking table' or 'associate table'. The linking
table links two tables by having fields which are the primary key of the other two tables. We can
understand this with the following example. Eg: If there are two entity type ‘Customer’ and ‘Product’
then each customer can buy more than one product and a product can be bought by many different
customers.
10. The difference among a relationship instance, a relationship type, and relationship set.
The relationship between various entities that belong to different entity types in a specific manner is
known as a relationship type.
A collection of various relationships that belongs to the same relationship type is called a relationship set.
Relationship present at particular instance of time is known as relationship instance and is shown in an
entity set. The relationship prepared between the two entity types: Salary Slips and Employees, associates
each salary slip with the employee who prepared it. Similarly, another example of relationship type of
STUDY_IN associates one student entity and one class entity. In this example, Student and Class are
entities and the relationship between i.e. STUDY_IN is the relationship set.
In the following ER diagram, the relationship types are shown in a diamond-shaped box. The participating
entities are shown in the rectangular boxes, which are connected to the diamond-shaped box through
straight lines.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
11. A database is being constructed to keep track of the teams and games of a sports league. A team
has a number of players, not all of whom participate in each game. It is desired to keep track of the
players participating in each game. Design an ER diagram for this application.
12. What are the components of ER diagram? Explain the function of various symbols use in ER diagram.
An Entity Relationship Diagram is a diagram that represents relationships among entities in a database. It
is commonly known as an ER Diagram. An ER Diagram in DBMS plays a crucial role in designing the
database. The major components of ER diagram are as follows:
These shapes are independent from other entities, and are often called
parent entities, since they will often have weak entities that depend on
Strong entity
them. They will also have a primary key, distinguishing each occurrence
of the entity.
Weak entities depend on some other entity type. They don't have
Weak entity primary keys, and have no meaning in the diagram without their parent
entity.
Associative entities relate the instances of several entity types. They also
Associative
contain attributes specific to the relationship between those entity
entity
instances.
Weak Weak Relationships are connections between a weak entity and its
relationship owner.
Multivalued Multivalued attributes are those that are can take on more than
attribute one value.
14. Explain the use of primary and foreign key in DBMS with example. What is the role of foreign key?
Primary Key: A primary key is used to ensure that data in the specific column is unique. A column cannot
have NULL values. It is either an existing table column or a column that is specifically generated by the
database according to a defined sequence.
Example: STUD_NO, as well as STUD_PHONE both, are candidate keys for relation STUDENT but STUD_NO
can be chosen as the primary key (only one out of many candidate keys).
Foreign Key: A foreign key is a column or group of columns in a relational database table that provides a
link between data in two tables. It is a column (or columns) that references a column (most often the
primary key) of another table. Example: STUD_NO in STUDENT_COURSE is a foreign key to STUD_NO in
STUDENT relation.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
15. Construct an E-R diagram for online book store where customers buy books online.
The set of attributes that are used to uniquely identify a weak entity set is called the Partial key. Only a
bunch of the tuples can be identified using the partial keys. The partial Key of the weak entity set is also
known as a discriminator.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)
Here we see a (strong) entity type “DogOwner” and a dependent weak entity type “Dog” that is connected
via the identifying relationship “owns”. The entity type “Dog” has attribute “name” which is not globally
unique (i.e., there might be more than one dog with the same name), but is unique for a certain dog owner
(i.e., an owner never owns two dogs with the same name). In this case “name” cannot be a (primary) key
of the entity type “Dog”, since it is not globally unique, but it is a partial key, because if we combine it with
the key of its owner we can uniquely identify a dog.
17. Construct an E-R diagram for online course registration where students register courses online.
18. In film industry, producers produce movies. Producers have their name, age and budget as
attributes. They are uniquely identified by prod_id. All the movies have their title, year, and release
date. No movies can have same title. Every movies must be played by actor. An actor can play many
movies. Actors have Fname and Lname to uniquely identify them. The actors have charge_rate as well.
A single movie can have many producers and a producer can produce many movies.
Prepared by Prabesh Bhandari (For 3rd Sem BIT, TU)