Database 2nd Mubashir 142
Database 2nd Mubashir 142
Section: SE-Red-2022
Subject: Database
Question # 1
Answer:
Question # 2
Answer:
Strong Entity Set:
A strong entity is independent and does not rely on any other entity for its existence. It always has a
primary key.
A weak entity, on the other hand, depends on a strong entity to ensure its existence. It lacks it own
primary key but instead has a partial discriminator key.
Redundancy result:
When we add the primary key attributes of the identifying strong entity to the weak entity, we introduce
redundant strong of the primary key. We duplicate information that already exists in strong entity. This
redundancy can lead to inefficacies in terms of storage space and maintenance. While converting a weak
entity set provides more robustness, it comes at the cost of redundant data storage. Careful
consideration is necessary to strike a balance between maintaining data integrity and minimizing
redundancy.
QUESTION:03
A library can have different types of books, and each book can have multiple copies. Each copy
in a library (belonging to some book type) has a unique ID. To borrow a book from the library,
one must be the member of the library. Once a person is issued with books copies, record is
maintained in database about the details of the person and the copies borrowed by him, e.g.,
some of the basic fields could be personid, copyid, borrowdate, returndate, persontype. A
person may be a student or a teacher. 2 The library staff can access the library database using
their user id and password. A staff member can insert the record of newly purchased books
copies in the library. The record may include basic details like seller, publisher, cost, number of
copies purchased, purchase date, record entered by, etc.
ANSWER
SELECT *
FROM Book_Copy
WHERE book_type_id = 2;
b) select details of book types.
ANSWER
SELECT *
FROM Book_Type;
(C) select details of copies issued by a given member.
ANSWER
ANSWER
SELECT Borrowing_Record.record_id, Person.name AS borrower_name, Book_Type.title AS
book_title, Book_Copy.copy_id, Borrowing_Record.borrow_date,
Borrowing_Record.return_date
FROM Borrowing_Record
JOIN Person ON Borrowing_Record.person_id = Person.person_id
JOIN Book_Copy ON Borrowing_Record.copy_id = Book_Copy.copy_id
JOIN Book_Type ON Book_Copy.book_type_id = Book_Type.book_type_id
WHERE Borrowing_Record.return_date < CURRENT_DATE;
(e) select details of copies that are processed by a given library staff member with some
name. (use like to match name).
ANSWER
SELECT Purchase_Record.purchase_id, Staff.name AS staff_name, Book_Type.title AS book_title,
Book_Copy.copy_id, Purchase_Record.purchase_date
FROM Purchase_Record
JOIN Staff ON Purchase_Record.record_entered_by = Staff.staff_id
JOIN Book_Type ON Purchase_Record.book_type_id = Book_Type.book_type_id
JOIN Book_Copy ON Book_Type.book_type_id = Book_Copy.book_type_id
WHERE Staff.name LIKE 'Admin Adminson';
QUESTION:04
A hospital has a large number of registered physicians. Attributes of PHYSICIAN include
Physician ID (the identifier) and Specialty. Patients are admitted to the hospital by physicians.
Attributes of PATIENT include Patient ID (the identifier) and Patient Name. Any patient who
is admitted must have exactly one admitting physician. A physician may optionally admit any
number of patients. Once admitted, a given patient must be treated by at least one physician.
A particular physician may treat any number of patients, or may not treat any patients.
Whenever a patient is treated by a physician, the hospital wishes to record the details of the
treatment (Treatment Detail). Components of Treatment Detail include Date, Time, and
Results. Draw the ERD and answer the following questions:
ANSWER
(i) Did you draw more than one relationship between physician and patient? Why or
why
not?
Yes, one is “Admit” and other is “Treats”
(ii) Did you include hospital as an entity type? Why or why not?
No, because hospital (entity) will have many more attributes and other
things which can be complex for this scenario.
(iii) Does your ERD allow for the same patient to be admitted by different physicians over
time?
How would you include on the ERD the need to represent the date on which a patient is
admitted for each time they are admitted
Yes.
QUESTION:05
For the following ERD, draw the tables on paper with proper links showing between foreign
keys and
primary keys
ANSWER