Palak Chaturvedi 2K20MC90 Assignment 1
Palak Chaturvedi 2K20MC90 Assignment 1
Assignment 1
Palak Chaturvedi
2K20/MC/90
Question 1)
Neeta has a large DVD movie collection. Her friends like to borrow her DVD's,
and she needs a way to keep track of who has what. She maintains a list of
friends, identified by unique FID’s (friend's identifier) and a list of DVD's
identified by DVDID's ( DVD's identifier). With each friend is the Name and all-
important telephone numbers which she can call to get the DVD back. With
each DVD is the star actor and actress name and movie title. Whenever a
friend borrows a Neeta will enter the fact into database along with the date
borrowed. Whenever the DVD gets returned, the fact too gets noted along
with the date returned. Neeta wants to keep a complete history of her friend’s
borrowing habits. Draw the ER diagram for this situation. Specify the entities,
relationships, attributes of entities and relationships, cardinality and
participation constraints and also the Primary Keys. Specify clearly any
assumptions that you have made. Suppose in the above question Neeta has a
large collection of music DVDs as well, where each music DVD is identified by
Unique DVDID and has an album_name. Neeta also lends her music DVDs to
her friends and records the borrowed date and returned date as well. What
changes in the ER diagram are required to include these facts? Map the given
ER schema into a relational schema. Specify all the primary and foreign keys.
Answer)
Entities:
Relationships:
1. Friend:
o FriendID (Primary Key)
o Name
o Telephone Number
2. DVD (Movie):
o DVDID (Primary Key)
o Star Actor
o Star Actress
o Movie Title
3. DVD (Music):
o DVDID (Primary Key)
o Album Name
4. Borrow:
o Borrow Date
o Return Date
o FriendID (Foreign Key referencing Friend entity)
o DVDID (Foreign Key referencing DVD entity)
Relational Schema:
Primary Keys:
1. Friend: FriendID
2. DVD: DVDID
3. Music_DVD: DVDID
4. Borrow: (FriendID, DVDID)
Foreign Keys:
Assumptions:
Question 2)
What role ER model plays in the Database Design Process?
Answer)
The ER model is a valuable tool in the database design process as it helps to:
Question 3)
Answer)
When a database designer encounters a multi-valued attribute, there are two
courses of action available:
Advantages:
• This approach provides better data integrity as it allows for separate
attributes for each value of the multi-valued attribute.
• It allows for easier querying of data as the multi-valued attribute is now a
separate entity.
• It provides a better representation of the data and its relationships.
Disadvantages:
• This approach can result in more complex data relationships and may
result in a larger number of tables in the database.
• It may also result in increased data redundancy.
For example, let's say a database designer is designing a database for a sports
team. The team has players and each player can have multiple positions.
Instead of having a multi-valued attribute "Position" for the player entity, the
designer can create separate single-valued attributes such as "Position1",
"Position2", etc.
Advantages:
• This approach is easier to implement and results in a simpler database
schema.
• It eliminates the need for additional entities and relationships.
Disadvantages:
• This approach may result in data redundancy as the same data may be
repeated for each value of the multi-valued attribute.
• It may also result in data inconsistencies as data may not be entered for
all values of the multi-valued attribute.
• It may not provide a clear representation of the data and its
relationships.
The choice between the two courses of action depends on the specific
requirements of the database and the nature of the multi-valued attribute. The
database designer must weigh the advantages and disadvantages of each
approach and make the best decision for the specific situation.
Question 4) Define redundancy with respect to data storage. How can the
database approach help in controlling redundancy?
Answer)
Redundancy in data storage refers to the repeated storage of the same data in
multiple places. This occurs when the same information is stored in multiple
records or tables, leading to a waste of storage space and potential
inconsistencies in the data.
4. Use of Views: A view is a virtual table that is derived from one or more
existing tables. By using views, the database designer can avoid the need
to store redundant data and ensure that the data is displayed in a
consistent manner.
Question 5)
The Hudson Engineering Group (HEG) has contacted you to create a
conceptual model whose application will meet the expected database
requirements of the company’s training program. The description of the
operating requirement is given below The HEG has 12 instructors and can
handle up to 30 trainees per class. HEG offers five advanced technology
courses each of which may generate several classes. If a class has fewer than
10 trainees, it will be cancelled. Therefore, it is possible for a course not to
generate any classes. Each class is taught by one instructor. Each instructor
may teach up to two classes or may be assigned to do research only. Each
trainee may take up to two classes per year. Draw the ER diagram for this
situation. (i) Identify the entities. Take suitable attributes for each one of them.
(ii) Identify relationships between/among entities.
(iii) Specify the cardinality constraints, participation constraints and min, max
constraint for each relation.
(iv) Specify the assumptions made if any
Answer)
ER Diagram:
i) Entities:
(ii) Relationships:
1. Instructor teaches Class - 1:N (1 instructor can teach multiple classes but
each class is taught by only 1 instructor)
2. Trainee takes Class - N:M (multiple trainees can take a class, and each
trainee can take multiple classes)
3. Course generates Class - 1:N (1 course can generate multiple classes, but
each class is generated by only 1 course)
4. Instructor instructs Trainee - 1:N (1 instructor can teach multiple trainees
but each is trainee can be taught by only 1 instructor)
Assumptions:
Each instructor has a unique instructor ID.
Question 6)
SHOP(Shop_No, Shop_name, Address, owner)
ITEM(I-No, I-Name)
SUPPLIED(I-No, C_No, Shop_No, Date, Price)
REQUIRES(C_No, I-No)
CUSTOMER(C_No, C_Name,C_Address)
SUPPLIED relation gives data about items supplied by a shop to a customer
and REQUIRES relation gives data about items required by a customer. Primary
keys of each relation are underlined.
(i) Write DDL statements to create these tables. Specify the Primary and
Foreign Key
constraints.
(ii) Write query statements for the following queries in SQL
(a). names of customers who have been supplied items of maximum
total
value.
(b). Names of customers who are supplied all the items from only "Jindal
Stores".
(c). List of shop owners who supplied some item to the address "Krishna
Nivas, MG Road"
Answer)
a.
SELECT C_Name
FROM CUSTOMER
WHERE C_No = (SELECT C_No FROM SUPPLIED GROUP BY C_No ORDER BY
SUM(Price) DESC LIMIT 1);
b.
SELECT C_Name
FROM CUSTOMER
WHERE NOT EXISTS (
SELECT I_No
FROM ITEM
WHERE NOT EXISTS (
SELECT I_No
FROM SUPPLIED
WHERE I_No = ITEM.I_No AND Shop_Name = 'Jindal Stores' AND
CUSTOMER.C_No = SUPPLIED.C_No
)
);
c.
SELECT Owner
FROM SHOP
WHERE EXISTS (
SELECT I_No
FROM SUPPLIED
WHERE SHOP.Shop_No = SUPPLIED.Shop_No AND C_Address = 'Krishna Nivas,
MG Road'
);