UNIT 2 QB
UNIT 2 QB
Entities are represented by means of their properties, called attributes. All attributes have values. For
example, a student entity may have name, class, and age as attributes.
Relationship Set
• A set of relationships of similar type is called a relationship set.
• Like entities, a relationship too can have attributes. These attributes are called descriptive attributes.
• Diamonds represent relationship sets.
• The main components of E-R model are: entity set and relationship set.
• It is a high-level data model. This model is used to define the data elements and relationship for a
specified system.
• It develops a conceptual design for the database. It also develops a very simple and easy to design
view of data.
One-to-many
One entity from entity set A can be associated with more than one entities of entity set B however an entity
from entity set B, can be associated with at most one entity.
Many-to-one
More than one entities from entity set A can be associated with at most one entity of entity set B, however
an entity from entity set B can be associated with more than one entity from entity set A.
Many-to-many
One entity from A can be associated with more than one entity from B and vice versa.
• 12.Define one to one mapping along with example. (Refer answer number 11)
• 13.Define one to one mapping along with example (Refer answer number 11)
• 14.Define one to many mapping along with example (Refer answer number 11)
• 15.Define many to one mapping along with example (Refer answer number 11)
• 16.Define many to many mapping along with example. (Refer answer number 11)
17.Differentiate strong entity set and weak entity set along with example.
Strong Entity Set
• An entity set which have enough number of attributes to form primary key is called as strong entity
set.
• An entity set that has a primary key using which, entities in the table can be uniquely identified.
This kind of entity set is termed as a strong entity set. Strong entity set is also known as a regular
entity set.
• In an ER diagram, the strong entity set is represented by the single rectangle.
ALTERNATE ANSWER
Example
• Generalization is the process of extracting common properties from a set of entities and create a
generalized entity from it.
• It is a bottom-up approach in which two or more entities can be generalized to a higher level entity if
they have some attributes in common.
• For Example, STUDENT and FACULTY can be generalized to a higher level entity called PERSON
as shown in Figure . In this case, common attributes like P_NAME, P_ADD become part of higher
entity (PERSON) and specialized attributes like S_FEE become part of specialized entity
(STUDENT).
For example: Center 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 center then he will
never enquiry about the Course only or just about the Center instead he will ask the enquiry about both.
Table: Domain:
• These constraints are used to describe the behaviour of foreign keys. A foreign key is a key of a
relation that can be referred in another relation.
• Example
12 MARKS
1.Explain the design issues in Entity relationship diagram along with example.
Ans.
ER Design Issues
1) Use of Entity Set vs Attributes
2) Use of Entity Set vs. Relationship Sets
3) Use of Binary vs n-ary Relationship Sets
>It is not always clear whether an object can be best expressed by an entity set or a relationship set.
>This approach is used to break such dilemma where a set of relationship is defined between entities with
designated action that has to occur between them.
>This approach can also be useful in deciding whether certain attributes may be more appropriately
expressed as relationships.
>Want to represent loans given to exactly one customer – Each loan is given at a particular bank branch
>In most cases the relationships in database system is binary which means it defines the relationship
between two entities.
>Sometimes a system may have non binary(more than 2) relations, under such design those non binary
relations are broken down to several binary relationships which in turn gives an easy and better
representation of the system.
The cardinality ratio in DBMS can help us determine in which scenarios we need to place relationship
attributes. It is recommended to represent the attributes of one to one or one to many relationship sets with
any participating entity sets rather than a relationship set.
For example, if an entity cannot be determined as a separate entity rather it is represented by the
combination of participating entity sets. In such case it is better to associate these entities to many-to-many
relationship sets.
3.Explain how Entity Relationship diagram is converted into tabular representation of schema along with
example.
• For each strong entity create a separate table with the same name.
• Includes all attributes, if there is any composite attribute divided into simple attributes and
has to be included.
• For each weak entity create a separate table with the same name.
• Include the P key of a strong entity as foreign key is the weak entity.
• Declare the combination of foreign key and decimator attribute as P key from the weak entity.
Step 3 − Conversion of one-to-one relationship
• For each one to one relation, say A and B modify either A side or B side to include the P key
of the other side as a foreign key.
• For each one to many relationships, modify the M side to include the P key of one side as a
foreign key.
• For each many-many relationship, create a separate table including the P key of M side and
N side as foreign keys in the new table.
• For each multivalued attribute create a separate table and include the P key of the present
table as foreign key.
• For each n-ary relationship create a separate table and include the P key of all entities as
foreign key.
Table
After successful conversion, the result will be as follows
If you have a multi-valued attribute, take the attribute and turn it into a new entity.
Add the primary (id) column of the parent entity as a foreign key within the new table.
=
Employee(empid, name, address, dob, sal)
Degree(empid, degree1, degree2,degree3)
Employee - empid(primary key)
Degree - empid(foreign key)
5.Explain the phases takes place in database lifecycle along with neat diagram.
6.Explain in detail about the components of ER model along with neat diagram.
Entity Set is a collection or a group of ‘entities’ sharing exactly the ‘same set of attributes’.
• All entities can be distinctly identified in an entity set. This is because all the entities have a
different set of value for some set of attributes.
classify the entity set into two basic categories Strong and Weak entity set.
An entity set that has a primary key using which, entities in the table can be uniquely identified. This
kind of entity set is termed as a strong entity set. Strong entity set is also known as a regular entity
set.
Attributes
Simple Attribute
Attributes are the properties which define the entity type. For example, Roll_No, Name, DOB, Age,
Address, Mobile_No are the attributes which defines entity type Student. In ER diagram, attribute is
represented by an oval.
Key Attribute
The attribute which uniquely identifies each entity in the entity set is called key attribute. For
example, Roll_No will be unique for each student. In ER diagram, key attribute is represented by an
oval with underlying lines.
Composite Attribute
An attribute composed of many other attribute is called as composite attribute. For example, Address
attribute of student Entity type consists of Street, City, State, and Country. In ER diagram, composite
attribute is represented by an oval comprising of ovals.
Multivalued Attribute
An attribute consisting more than one value for a given entity. For example, Phone_No (can be more
than one for a given student). In ER diagram, multivalued attribute is represented by double oval
Derived Attribute
An attribute which can be derived from other attributes of the entity type is known as derived
attribute. e.g.; Age (can be derived from DOB). In ER diagram, derived attribute is represented by
dashed oval
Relationship
For example, an employee works_at a department, a student enrolls in a course. Here, Works_at and
Enrolls are called relationships
Relationship Set
o A set of relationships of similar type is called a relationship set. Like entities, a relationship
too can have attributes. These attributes are called descriptive attributes.
Degree of Relationship
o The number of participating entities in a relationship defines the degree of the relationship.
▪ Binary = degree 2
▪ Ternary = degree 3
▪ n-ary = degree
- Savings-Account
- Checking-Account
- Payment (Weak)
Step 2) Relationship Identification
- Customer can borrow a loan or deposit cash
- Deposited cash will be logged into a register and will be connected to an account
- Deposited cash goes into the Savings-Account
- Customer may himself be an employee at the bank and may get some extra benefits
- Loan can be given at different rates depending on the branch
Step 3) Cardinality Identification
- A customer can have many accounts
- A customer can have multiple loans
- Loan will be provided by exactly 1 branch
Step 4) Attributes Identification
- Account
- Savings-Account
- Interest Rate
- Checking-Account
- Overdraft Amount
- Customer
- ID, Name, Address, City
- Employee
- ID, Name, Hire-date, Contact, Manager_Name, Designation
- Branch
- ID, Name, City
- Loan
- ID, Amount, Interest, Branch
- Payment
- ID, Date, Amount
HCity
HAddress
Hos-Name
Patient
PName
PAddress
PDiagnosis
Medical Record
Problem
Date_of_examination
Doctor
DName
Qualification
Salary
• Composite Attributes
Composite Attributes which can be divided into subparts.
Example: Patient Name, Doctor Name
Pat-id Hospital table makes foreign key references to Pat-id of Patient table
Hosp-id Patient table makes foreign key references to Hosp-id of Hospital table
Hosp_Doctor
Hosp-id Doctor table makes foreign key references to Hosp-id of Hospital table
Doc-id Hospital table makes foreign key references to Doc-id of Doctor table
PatiPPatient_MedicalRecord
Pat-id Medical Record table makes foreign key references to Pat-id of Patient table
Record-id Patient table makes foreign key references to Record-id of Medical Record table
10.Explain relational model and constraints defined in relational model along with example.
Relational model.
• The relational model for database management is an approach to logically represent and manage the
data stored in a database.
• In this model, the data is organized into a collection of two-dimensional inter-related tables, also
known as relations.
• Each relation is a collection of columns and rows, where the column represents the attributes of an
entity and the rows (or tuples) represents the records.
• The use of tables to store the data provided a straightforward, efficient, and flexible way to store and
access structured information. Because of this simplicity, this data model provides easy data sorting
and data access. Hence, it is used widely around the world for data storage and processing.
Concepts: Tables, Tuple, Relational Instance, Relation Schema, Relation Key, Attribute Domain
Every relation has some conditions that must hold for it to be a valid relation. These conditions are called
Relational Integrity Constraints. There are three main integrity constraints –
Domain Constraints are user-defined columns that help the user to enter the value according to the data type.
And if it encounters a wrong input it gives the message to the user that the column is not fulfilled properly.
Or in other words, it is an attribute that specifies all the possible values that the attribute can hold like
integer, character, date, time, string, etc. It defines the domain or the set of values for an attribute and
ensures that the value taken by the attribute must be an atomic value(Can’t be divided) from its domain.
There are two types of constraints that come under domain constraint and they are:
3. Domain Constraints – Not Null
4. Domain Constraints – Check
Example:
Table: Domain: