0% found this document useful (0 votes)
22 views

DBMS 2022-23 Midsem

Schema 4 and Schema 5 provide efficient relational schemas to store the employee email information. Schema 4 separates the employee information and email ids into two tables to avoid null values. Schema 5 also separates this information but ensures all employees have an office email id, and only those with additional emails are stored in the second table. The example of employee emails is different from person hobbies in that the same email cannot belong to multiple people, but a hobby can belong to multiple people. The extent that is not possible for the works_in relationship based on the "look here" mapping convention is option (a) since a person cannot belong to more than one department according to this convention.

Uploaded by

Prateek Talwar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

DBMS 2022-23 Midsem

Schema 4 and Schema 5 provide efficient relational schemas to store the employee email information. Schema 4 separates the employee information and email ids into two tables to avoid null values. Schema 5 also separates this information but ensures all employees have an office email id, and only those with additional emails are stored in the second table. The example of employee emails is different from person hobbies in that the same email cannot belong to multiple people, but a hobby can belong to multiple people. The extent that is not possible for the works_in relationship based on the "look here" mapping convention is option (a) since a person cannot belong to more than one department according to this convention.

Uploaded by

Prateek Talwar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, K.K.

BIRLA GOA CAMPUS


Second Semester 2022-2023
Course Title: Database Systems Course No: CS F212
Component: Midsem Test (Regular) Mode: Closed book
Weightage: 27% Max Marks: 54 Time: 9:00 to 10:30 a.m. Date: 13/03/2023

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.

Following answers are correct


Schema 4: EmployeeRelation (Eid, Ename) and EmployeeEmailids (Eid, Emailid)
This schema is efficient as the employee having multiple emailids is stored separately.

Schema 5: EmployeeRelation (Eid, Ename, officeemailid) and EmployeeEmailids (Eid, Emailid)


This schema is efficient as all the employees have office email id and only those having personal
emailids or positions are stored in the EmployeeEmailids table.

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.

QA3. Map the given EER model to the Relational model.

Ans: Cars ( LicenseNo., Manufacturing Year, State, Mileage, Type )


PetrolCars (LicenseNo., Tank capacity)
DieselCars (LicenseNo., Tank capacity)
GasCars (LicenseNo., Cylinder capacity)
ElectricCars (LicenseNo., Battery capacity)

OR

Cars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Fuel-type, Petrol_Tank capacity,
Gas, Cylinder_capacity, battery_capacity )

OR

Cars ( LicenseNo., Manufacturing Year, State, Mileage, Type, Fuel-type, capacity )

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?

Person = { John, Jack, Jill } and Dept { ‘CS, ‘Math’, ‘Science’ }

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.

a: As a person cannot belong to more than one department

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?

R: select D.cust_name from Branch


B, Accounts A, Depositor D where
B.branchname=A.branchname and
A.accountno =D.accountno and
B .branchcity= “Mumbai”;

S: select D.cust_name from Accounts A, Depositor D where A.accountno = D.accountno and


A.branchname in (select B.branchname from Accounts B where B.branchname in (select
R.branchname from Branch R where branchcity= “Mumbai”));
Ans: S. since no of records compared for Mumbai branch in S are less than in P due to innermost
query in S is executed first.

QC3. Consider the following database:


Books (ISBN, Title, Edition, year, PublisherID, pages, price, Language)
Writers (WriterID, Name, Birthplace, Nationality)
Authors (ISBN, WriterID)
Publishers (PublisherID, Name, Place, Nationality)

Write an efficient query in relational algebra to


a. List the id of the writers who have written books in two (or more) different languages.

Temp1  Π ISBN, WriterID, Language ( Books |X| Authors )


ρTemp2(Temp1)
Π WriterID σ( Temp1.WriterID = Temp2.WriterID ^ Temp1.Language < > Temp2.Language) (Temp1 X Temp2)

b. List the name of the writers who have published at least one book with “Korth”.

If “Korth” is considered an author.

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)

If “Korth” is considered as a publisher.

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)

QC4. Explain in plain English what does the query find?


Select ISBN, WriterID from Authors group by ISBN having count(*) > 1;
Ans: List the books written by more than one author.

QC5. Are the following queries equivalent? Justify.

q1. ∏ ISBN (σ Name = ‘Korth’ ( Writers |X| Authors)  ∏ isbn (σ Name = ‘Sudarshan’ ( Writers |X| Authors )
q2. ∏ ISBN (σ Name = ‘Korth’ Λ Name = ‘Sudarshan’ ( Writers |X| Authors )

W1 ( ∏ ISBN,WriterID (σ Name = ‘Korth’ Writers |X| Authors) )


W2 ( ∏ ISBN,WriterID (σ Name = ‘Sudarshan’ Writers |X| Authors) )
q3. ∏ ISBN (σ W1.WriterID < > W2.WriterID ^ W1.ISBN = W2.ISBN (W1 X W2))

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?

custid Custname Salesperson_id Salesperson_name region


C1 AA SN XX North
C2 BB SS YY South
C3 AA SE ZZ East
C4 CC SW XX West
C5 DD SN WW North

Deletion anomaly: If a salesperson temporarily has no customer, its information (salesperson_id,


salesperson_name, region) will not be represented in the database when the last customer is
removed. Example: As SW has only one employee, on deleting the C4 record, details of
salesperson SW are also lost.
Insertion anomaly: A new salesperson cannot be added unless at least one customer is assigned.
Example: Following insertion is not accepted as custid cannot be NULL because it is a primary
key. {NULL, NULL, SW, XX, West}

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.

QD2. Consider the following relation for published books:


BOOK (Book_title, Author_name, Book_type, Listprice, Author_affil, Publisher)
Author_affil refers to the affiliation of the author. Suppose the following dependencies exist:
Book_title  Publisher, Book_type
Book_type  Listprice
Author_name  Author-affil
Decompose the relation BOOK to the best normal form. Mention the type of normal forms.

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.

{ Book_title, Author_name }+ = { Book_title, Author_name, Publisher, Book_type, Author-affil,


} : from FD1 and FD3
{ Book_title, Author_name }+ = { Book_title, Author_name, Publisher, Book_type, Author-affil,
Listprice } : from FD2
This is the same as the BOOK relation. Thus Book_title, Author_name can be the composite
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.

Step 3: 3NF decomposition:


Book1 ( Book_title, Authorname )
Book21 ( Book_title, Publisher, Book_type)
Book22 ( Book_type, Listprice)
Book3 ( Authorname, Author_affil)

This decomposition eliminates the transitive dependency of Listprice


This decomposition is also in BCNF because each key determines the non-key attribute.

QD3. Consider the relation R(W,X,Y,Z) and the function dependencies:


F = {WX -> Y, X -> Z, Y -> W}
Decompose the relation R to the best normal form. Mention the type of normal forms.
Ans:
 For the first FD WX -> Y, since WX is a key for R, it does not violate BCNF.
 Second FD, X -> Z violates BCNF as X is not a key. Thus we create two relations (XZ)
and (WXY).
Now inspect the given two relations for BCNF,
For (XZ), the candidate key is X. The only FD that applies here is X -> Z, so it is in BCNF.
For (WXY), the candidate keys are WX and XY.

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)

QD4. Test whether the following FDs are equivalent:


F = { B → A, AD → C, C → BD } and G = { B → A, AD → BC, C → ABD }

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.

Ans: On expanding F, we get


1. X → W
2. WZ → X
3. WZ → Y
4. Y → W
5. Y → X
6. Y → Z

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***

You might also like