DBMS 2022-23 Midsem
DBMS 2022-23 Midsem
Instructions: Start each section on a new page. Make an Index (Section no., Page no.) on the first
page. Strictly answer in sequential order only.
Note: 2 marks will be reduced for not following the instructions and/or not writing the correct
question number, Name, ID.No. The examiner keeps the right not to evaluate the answer if the
answers are unreadable and trouble her eyes.
Section A [ 3 + 4 + 3 + 3 = 13 Marks ]
QA1. Suggest the efficient relational schema with required constraints for the following. Every
employee of an organization is provided an email-id. He/she may have multiple email ids like
personal email ids and if the employee holds an administrative position like head, dean, director,
etc, the organization also provides one more email-id to the employee as per the position. For
example, if John is head of the accounts department in XYZ organization, he may have the
following email ids, [email protected], [email protected], and [email protected].
Ans: Following answers are incorrect due to the reasons given below:
Schema 1: EmployeeRelation (Eid, Ename, personal_emailid, office_emailid1, postion_emailid2)
Inefficient because those without personal email id or not having any position will have NULL
values thus wasting the space.
Schema 2: EmployeeRelation (Ename, personal_emailids, office_emailid1, postion_emailid2)
Inefficient because employees without personal email ids are not accepted by this schema.
Schema 3: EmployeeRelation (Ename, personal_emailid, office_emailid1, postion_emailid2)
Inefficient because searching based on office emaild is difficult.
QA2.
Map the above ER model to the Relational model with the following constraints.
Each team has one captain and the same player cannot be the captain of more than one team.
You may add the captain_id column if needed that refers to Pid in the Players table.
Ans:
1
1. By adding a column Teamid in Players table as a foreign key referring to Teamid of Teams
table with ‘NOT NULL’ constraint on Teamid.
2. By adding a column Captain_id in the Teams table as foreign key referring to Pid of Players
table with ‘Unique’ and ‘NOT NULL’ constraints on Captain_id. (if both Teamid and
Captain_id are made composite primary key, one player can be captain of more than one
team. Thus the composite key is the wrong answer. For eg: T1 P1, T2 P1 are together
unique which will be accepted but it is logically incorrect.) Here Not Null constraint on
captain_id takes care of total participation of all teams by allocating at least one player to
the team.
If a separate table is made for belong_to with Player_ID and Team_ID together as
composite key, then some players which are in Player table may not be included in the
belongs_to table which means the total participation constraint is violated.
OR
Cars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Fuel-type, Petrol_Tank capacity,
Gas, Cylinder_capacity, battery_capacity )
OR
The following answer is incorrect because as the diagram shows partial participation, those cars
for which we do not have information about its category, can’t be stored.
PetrolCars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Tank capacity )
DieselCars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Tank capacity )
2
GasCars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Cylinder capacity )
ElectricCars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Battery capacity )
The following answer is incorrect because as the diagram shows disjoint, only one value will be
filled and others will be NULL
Cars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Petrol, Tank capacity, Diesel, Tank
capacity, Gas, Cylinder capacity, Electric, battery capacity )
QA4. Draw an ER/EER diagram representing the following information. The student has to
complete multiple lab assignments for a course. The students are allowed to make multiple
submissions for these lab assignments before their deadline. Each submission is noted with a
version number and the date and time when it was submitted. A drive link of the assignment
question is shared with the students and the students upload their submissions in the form of a file.
Section B [ 2 + 2 + 4 = 8 Marks]
QB1. Explain how is the example in QA1 same/different from a person who can have many
hobbies.
Ans: Same hobby can belong to different person but the email id cannot belong to another person.
This emailid is an example of multivalued attribute and hobbies is an example of one is to many
mapping constraints.
QB2. Which is/are not a possible extent of works_in according to the look-here mapping
cardinality convention? Explain why?
a. {(John,Math),(John,CS),(Jill,Math),(Jack,Math)}
b. {(John,Math),(Jill,Math),(Jack,Math)}
c. {(John,CS),(Jill,Math),(Jack,Math)}
d. {(John,CS),(Jill,Math),(Jack, Science)}
e. {(John,CS),(Jill,Math)}
3
Ans: According to the ‘Look Here’ convention, the mapping constraints are: A person may not
belong to any dept but if it belongs to any then at the max to only one dept. A dept can have zero
to many people.
QB3. Write an assertion to guarantee that each manager’s salary is more than 50K. If someone
makes a manager whose salary is less than 50K that insertion/update to the dept table will be
rejected. Furthermore, if the manager’s salary is reduced to less than 50K, the corresponding
update to the emp table will be rejected.
Ans:
CREATE ASSERTION RichMGR CHECK (NOT EXISTS
(SELECT *
FROM dept, emp
WHERE emp.name = dept.mgrname AND emp.salary < 50000))
Section C [ 2 + 2 + 9 + 2 + 3 = 18 Marks ]
QC1. Given two queries P and Q which gives the same result, test the efficiency of the query by
finding the number of disk accesses required. Assume T(Staff)=1000, T(Branch)=50, 50 managers
(one for each branch). Also, assume there are no indexes or sort keys on both the relations and that
the results of any intermediate operations are stored on disk. Ignore the cost of the final writes as
it is the same in each case. The tuples are accessed one at a time and the main memory is large
enough to process entire relations.
P.σ(position=‘Manager’) ^ (city= ‘Vasco’) ^ (staff . branchno = Branch . branchno) (Staff X Branch)
Q.σ(position=‘Manager’) ^ (city= ‘Vasco’) (Staff staff . branchno = Branch . branchno Branch)
Ans:
P: The query first calculates the Cartesian product of Staff and Branch, which requires (1000 +
50) disk accesses to read the relations, and creates a relation with (1000 * 50) tuples. We then have
to read each of these tuples again to test them against the selection predicate at a cost of another
(1000 * 50) disk access, giving a total cost of:
(1000 + 50) + 2*(1000*50) = 101 050 disk accesses.
Q: The query joins Staff and Branch on the branchno, which requires (1000 + 50) disk accesses to
read each of the relations. The joining of the two relations has 1000 tuples, one for each member
of staff (a member of staff can only work at one branch). Consequently, the selection operation
requires 1000 disk accesses to read the result of the join, giving the cost of:
2*1000 + (1000 + 50) = 3050 disk accesses.
4
QC2. Given two queries R and S which gives the same result, explain which one you would choose
for efficient query processing and why?
b. List the name of the writers who have published at least one book with “Korth”.
Step 1: Find the isbn of the book written by Korth by performing natural join on Writers and
Authors.
Temp1 Π ISBN σ Name = “Korth” ( Writer |X| Authors )
Step 2: Find the isbn of the books not written by Korth or written by authors other than Korth
Temp2 Π ISBN σ Name < > “Korth” ( Writer |X| Authors )
Step 3: perform cross-product of Temp1 and Temp2 and find another WriterID for same book
Temp3 ΠTemp1.WriterID (σ( Temp1.WriterID < > Temp2.WriterID ^ Temp1.ISBN = Temp2.ISBN) ) (Temp1 X Temp2))
5
Step 4: To find the corresponding name of the writer, perform natural join on Temp3 and
Writers relation
Π Name ( Temp3 |X| Writers)
Step 1: Find the isbn of the book published by Korth by performing natural join on Publishers
and Books.
Temp1 Π ISBN σ Name = “Korth” ( Publishers |X| Books )
Step2: Find the corresponding writer by performing natural join on Temp1 and Authors.
Temp2 Π WriterID ( Authors |X| Temp1 )
Step 3: To find the corresponding name of the writer, perform natural join on Temp2 and
Writers relation Π Name ( Temp2 |X| Writers)
c. List the publisher name who has never printed a book written by an “Italian” writer.
Step1: List the isbn of the books published by Italian authors by performing natural join on
Writers and Authors.
Temp1 Π ISBN σ Nationality = “Italian” ( Writer |X| Authors )
Step2: Find the corresponding publisher by performing natural join on Temp1 and Books.
Temp2 Π PublisherID ( Books |X| Temp1 )
Step 3: Publishers have the list of all publishers including those who have not yet published
any book. Thus remove the publishers in list Temp2 from Publisher relation to find those who
have never printed a book written by an Italian writer.
Temp3 Π PublisherID ( Publishers ) – Temp2
Step 4: To find the corresponding name of the publisher, perform natural join on Temp3 and
Publishers relation
Π Pubishername ( Temp3 |X| Publishers)
q1. ∏ ISBN (σ Name = ‘Korth’ ( Writers |X| Authors) ∏ isbn (σ Name = ‘Sudarshan’ ( Writers |X| Authors )
q2. ∏ ISBN (σ Name = ‘Korth’ Λ Name = ‘Sudarshan’ ( Writers |X| Authors )
6
Ans: q1 and q3 are equivalent as both the queries find the book ISBN written by both Korth and
Sudarshan.
query q2 gives an error as the same attribute cannot be used in and predicate.
Section D [ 3 + 3 + 3 + 3 + 3 = 15 Marks]
QD1. Consider the relation Sales (custid, custname, salesperson_id, salesperson_name, region).
Each customer is associated with only one salesperson. A salesperson can cater to zero or more
than one customer. A salesperson takes care of only one region and each region i.e. North, East,
West, and South has only one salesperson. What anomalies occur in the Sales relation?
Following entry is accepted which is invalid because SW is a salesperson of West region but
entered for North which causes inconsistency.
{C6, EE, SW, XX, North} or {C6, EE, SW, XX, Wst}//e is missing//incorrect spelling
Update anomaly:
If the region of a certain salesperson is changed or spelling needs to be corrected, it has to be
changed all over consistently.
Ans: Let
7
FD1: Book_title Publisher, Book_type
FD2: Book_type Listprice
FD3: Author_name Author-affil
Step 1: Find the candidate keys by finding the closure of LHS of each FD.
{ Book_title }+ = { Book_title, Publisher, Book_type, Listprice } : from FD1 and FD2
This is not the same as the BOOK relation. Thus Book_title cannot be the primary key.
{ Book_type }+ ={ Book_type, Listprice } : from FD2
This is not same as BOOK relation. Thus Book_type cannot be the primary key.
{ Author_name }+ = { Author_name, Author-affil } : from FD3
This is not the same as the BOOK relation. Thus Author_name cannot be the primary key.
Step 2: This relation is in 1NF as each attribute is atomic and there is no multivalued attribute. It
is not in 2NF as there exist partial dependencies.
2NF decomposition:
Book1( Book_title, Authorname )
Book2(Book_title, Publisher, Book_type, Listprice)
Book3(Authorname, Author_affil)
This decomposition eliminates the partial dependencies.
8
1. The first FD applies, WX -> Y, and WX is a key, so it is in BCNF.
2. The second FD doesn’t apply (there is any Z in it).
3. The third FD, Y->W, Y, is not a super key; thus, we need to decompose by creating a
new relation.
(XZ)(YW)(XY)
XZ: The XZ is still in BCNF as before.
YW: The YW has Y as the candidate key, and the only FD that applies is Y-> W. It is in
BCNF.
XY: XY has XY as the candidate key, and no FDs apply, so it is in BCNF.
Thus our final decomposition is:
(XZ)(YW)(XY)
Ans: Find the closure of both the sets and check if they are same.
F = { B → A, AD → C, C → B, C → D }
From second and third FD, by applying transitivity rule, we get, AD → B
Similarly from third and first FDs, we get, C → A
Thus F+ = { B → A, AD → C, C → B, C → D, AD → B, C → A }
G+ = { B → A, AD → B, AD → C, C → A, C → B, C → D }
As F+ is same as G+, the FDs F and G are equivalent.
QD5. The following functional dependencies hold for the relational scheme R ( W, X, Y, Z )
F:{ X → W, WZ → XY, Y → WXZ}
Find the canonical cover of F.
By applying Armstrong axiom 3 i.e transitivity rule, FD 2 can be derived from FD 3 and FD 5.
Thus FD 2 can be removed from set F.
Similarly, FD 4 can be derived from FD 5 and FD 1. Thus FD 4 can be removed from set F.
Thus the canonical cover of F is { X → W, WZ → Y, Y → XZ }
***Reminder: Fill in the Index, Ensure IDNO. and Name is written on all the sheets***