You are on page 1of 23

BSCCS2001: Mock Quiz with Solutions

Weeks 1 to 4
1. Which of the following option aptly describes the scalability property of DBMS?

[MCQ:2points]

The system can efficiently adapt to a rapidly growing data set.
⃝ The data survives even if the system crashes abruptly.
⃝ The business logic associated with the data is always kept intact.
⃝ None of the above

Solution:
In the context of DBMS, scalability means the efficient adaptation of performance
of the system to a rapidly growing data set.

Page 2
2. Consider the entity set given in Figure 1. [MCQ: 4 points]

Figure 1: Entity set

Identify the statement which CORRECTLY describes the attributes of the entity set
Gamer.

gamer id: primary key
gamer name: composite attribute
email ids: multivalued attribute
play time: derived attribute
⃝ gamer id: primary key
gamer name: composite attribute
play time: multivalued attribute
join time: derived attribute
⃝ play time: primary key
gamer name: composite attribute
gamer id: multivalued attribute
fname: derived attribute
⃝ email ids: primary key
fname: composite attribute
email ids: multivalued attribute
gamer name: derived attribute

Solution: The different attributes are identified as shown in Figure 2.

Page 3
Figure 2: Identification of different types of attributes

Page 4
3. Consider the following statements:

• SQL can be used to perform complex arithmetic operations.


• File based data management systems ensure consistency of data all the time.

The number of correct statements is


[MCQ:2 point]
Ans: 0

Solution:
Performing complex arithmetic operations are difficult using SQL.
File based data management systems may not be able to ensure consistency of data
all the time, since the relationships and constraints are enforced via file handling
programs. On the other hand, a DBMS has in-built mechanisms to ensure all-time
consistency of data.
Therefore, none of the given statements are true.

Page 5
4. Using the table Students in Figure 3, choose the correct SQL statement that will return
the table shown in Figure 4.

Figure 3: Table Students

Figure 4: Resultant table

[MCQ: 2 points]
⃝ SELECT Country, SUM(Score) AS Sum
FROM Students
GROUP BY Age HAVING AVG(Score)>100 AND AVG(Age)>12;
⃝ SELECT Country, SUM(Score) AS Sum
FROM Students
GROUP BY Age HAVING SUM(Score)>150 AND AVG(Age)>13;
⃝ SELECT Country, SUM(Score) AS Sum
FROM Students
GROUP BY Country HAVING AVG(Score)>70 AND AVG(Age)>13;

SELECT Country, SUM(Score) AS Sum
FROM Students
GROUP BY Country HAVING SUM(Score)>100 AND AVG(Age)>12;

Solution: The GROUP BY clause is used to group data based on specific values of
the given attribute.
The SUM function returns the total sum of a numeric column.
The resultant table will be fetched by applying GROUP BY clause on Country that

Page 6
together will have sum of score greater than 100 and the average age is more than
12.

Page 7
5. Use the tables in Figure 5 to answer the question that follows.

Figure 5: Table suppliers and table parts

Let {sup num} be the primary key of table suppliers and {part num, sup num} be the
primary key of table parts. [NAT: 3 points]
Consider the SQL query given below:

SELECT s.sup_num, sum(p.part_qty)


FROM suppliers s, parts p
WHERE p.part_qty > 30
GROUP BY s.sup_num

How many rows will be returned by the above SQL query?


Answer: 4

Solution: As per the given SQL statement, it first obtains the Cartesian product
between suppliers and parts, which include all possible combinations from both
the tables.
The part of the statement:
WHERE p.part qty > 30
eliminates the rows which do not satisfy the condition. The output is as shown
below:

Page 8
Finally, the part of the statement:
SELECT s.sup num, sum(p.part qty) ...GROUP BY s.sup num
results in:

Thus, the result has 4 rows.

Page 9
6. Consider relations as given below: [MCQ: 2 points]

userMaster(userid,userName,email,phone)
passwHistory(userid,password,status)

Which among the following SQL statements will return the valid password(s) of user(s)
whose userid ends with “001”?
⃝ SELECT password FROM userMaster OUTER JOIN passwHistory
WHERE userMaster.userid LIKE "%001" AND status = "VALID";
⃝ SELECT password FROM userMaster, passwHistory
WHERE userMaster.userid LIKE "%001" AND status = "VALID";

SELECT password FROM userMaster NATURAL JOIN passwHistory
WHERE userMaster.userid LIKE "%001" AND status = "VALID";
⃝ SELECT password FROM userMaster INNER JOIN passwHistory
WHERE userMaster.userid LIKE "%001" AND status = "VALID";

Solution: NATURAL JOIN is a join operation that joins two tables using the common
columns of the two tables. Here, the common column is userid and hence the
NATURAL JOIN finds rows with same values for userid. The other two constraints
are added as conditions under the WHERE clause.

Page 10
7. Consider tables Employee, Department and Dependent, and answer the question
that follows. [MCQ: 3 points]

Choose the correct query to retrieve the name of each employee who has a dependent
with the same name and the same sex as that of the employee.
⃝ SELECT name FROM Dependent as E
WHERE EXISTS ( SELECT * FROM Employee as D WHERE E.ssn = D.essn OR
E.sex = D.sex AND E.name = D.dep_name );
⃝ SELECT name FROM Employee as E
WHERE NOT IN ( SELECT * FROM Employee as D WHERE E.ssn = D.essn OR
E.sex = D.sex AND E.name = D.dep_name );

SELECT name FROM Employee as E
WHERE EXISTS ( SELECT * FROM Dependent as D WHERE E.ssn = D.essn AND
E.sex = D.sex AND E.name = D.dep_name );
⃝ SELECT name FROM Dependent as D
WHERE NOT EXISTS ( SELECT * FROM Employee as E WHERE E.ssn = D.essn AND
E.sex = D.sex AND E.name = D.dep_name );

Page 11
Solution: The EXISTS condition in SQL is used to check whether the result of a
correlated nested query is empty (contains no tuples) or not.
SQL NOT IN operator is used to filter the result if the values that are mentioned as
part of the IN operator is not satisfied.
As we have to retrieve the name of each employee who has a dependent with certain
given condition, the outer query needs to fetch data from the table Employee and
inner query from the table Dependent. Hence Option 1 and 4 are incorrect.

For option 3 - The inner query will retrieve all the data from the table dependent,
where the name, sex and ssn of each employee is matched with the dependent. Hence,
it will return something and the EXISTS condition will become TRUE, and based on
that, the outer query will fetch the name(s) of those employees who has a dependent
with the same first name and is of the same sex as that of the employee.

For option 2 - In the inner query, the condition of ssn and sex are separated by OR
(it has to be ‘AND’ as per the question’s requirement). Also, the NOT IN keyword
will look for the values which is not in the set returned by the inner query. Hence
the desired result will not be fetched.

Page 12
8. Consider the relational schema given in Figure 6.

Figure 6: Country Capitals Relational Schema

Choose the correct option(s) to fill in the blanks in the query given below to find the
capitals of all those countries that belong to both Asia and Europe.
[MSQ: 3 points]

SELECT capitalName FROM capital


WHERE _______________ (
(SELECT countryID FROM country
WHERE continent =‘Asia’
AND capital.countryid = country.countryid)
_______________
(SELECT countryID FROM country
WHERE continent =‘Europe’
AND capital.countryid = country.countryid));

EXISTS, INTERSECT
⃝ NOT EXISTS, UNION
⃝ EXISTS, UNION
⃝ NOT EXISTS, INTERSECT

Solution: The inner query of the first option returns all countries which belong to
Asia and Europe. Hence it is correct.
The inner query of the second option returns all countries that are not in the set of
countries that belong to either Asia or Europe. This is incorrect.
The inner query of the third option returns all countries that belong to either Asia
or Europe. We need countries that belong to both and hence this option is also
incorrect.
The inner query of the fourth option filters out those countries that belong to both
Asia and Europe. This is also incorrect.

Page 13
9. Find the equivalent relational algebraic expression corresponding to the below SQL state-
ment: [MCQ: 2
points]

SELECT id FROM classFour WHERE id > 5


EXCEPT
SELECT id FROM classFour WHERE id > 10;
Q 
⃝ id σid∈{5,6,7,8,9,10} (classFour)
Q 
⃝ id σid>5 ∧ id>10 (classFour)
√ Q 
id σid>5 ∧ id≤10 (classFour)
Q 
⃝ id σid>5 ∨ id>10 (classFour)

Solution: The EXCEPT clause in SQL is used to get the rows returned by the
first statement that are not returned by the second statement. The first statement
returns all id s greater than 5 and the second statement returns all id s greater than
10. Hence, the rows retuned by the complete SQL statement will correspond to the
Qs in the set {6, 7, 8, 9, 10}. This is obtained by the relational algebra expression:
id
id σid>5 ∧ id≤10 (classFour) .

Page 14
10. Given the relations R1 , R2 as shown in Figure 7, choose the relation that results from
R1 ÷ R2 .
[MCQ:2 points]

A B
a1 b1
a1 b2 A
a2 b1 a1
a3 b1 a2
a3 b2 a3
a1 b3 Relation R2
a2 b3
Relation R1
Figure 7: Relations R1 and R2

B
b
⃝ 1
b2
b3
B
a1

a2
a3
√ B
b1
A

a1

Page 15
11. Consider the entity sets MOVIE and PERSON with a many-to-many relationship set
WATCHES as shown in Figure 8 and answer the question that follows.

Figure 8: E-R diagram

If we wish to store the ticket number of a ticket purchased by a person for a movie, then
in which among the following must this information appear?
[MCQ: 3 points]

⃝ PERSON

WATCHES
⃝ MOVIE
⃝ WATCHES or PERSON
⃝ WATCHES or MOVIE
⃝ PERSON or MOVIE
⃝ WATCHES or PERSON or MOVIE

Solution: Since there is a many-to-many relationship between PERSON and MOVIE,


it follows that the ticket payment information must be added as a descriptive at-
tribute of WATCHES relationship set.

Page 16
12. Let X(A, B) and Y(C, D) be two relations with instances as shown in Figure 9.
[MCQ:4 points]

Figure 9: Relations X and Y

Find the number of tuples returned by the following query:


ΠA (σB=C (X × Y )) - ΠA (σA=D (X × Y ))
⃝ 9
⃝ 3
⃝ 2

None of the above

Solution: (X × Y )

ΠA (σB=C (X × Y ))

ΠA (σA=D (X × Y ))

Page 17
ΠA (σB=C (X × Y )) - ΠA (σA=D (X × Y ))

So,the number of tuples is 1. Thus, option 4 is correct.

Page 18
13. Consider two relational schemas as follows: [MCQ: 3 points]
employees (emp num, emp name, salary, dept num)
departments (dept num, dept name)

Suppose the instances (tables) for employees and departments relations have 30 tuples
and 50 tuples respectively. What will be the number of tuples and the number of
attributes in the table resulting from executing the following SQL statement?

SELECT * FROM employees, departments


⃝ number of tuples = 50, number of attributes = 4

number of tuples = 1500, number of attributes = 6
⃝ number of tuples = 1500, number of attributes = 5
⃝ number of tuples = 50, number of attributes = 5

Solution: The SQL statement represents Cartesian product between the two tables,
which generates all possible combinations of the tuples from both the tables. If we
take the Cartesian product of two relational instances having n1 and n2 number
of tuples, and m1 and m2 number of attributes then the resulting table must have
n1 × n2 tuples and m1 + m2 attributes.

Page 19
14. Consider two relations as shown in Figure 10: [MCQ: 3 points]

Figure 10: Relations course 2019 and course 2020

Identify the correct operation that results in the output shown in Figure 11.

Figure 11: Output relation

⃝ courses 2019 − courses 2020



courses 2020 − courses 2019
⃝ courses 2020 ∩ courses 2019
⃝ courses 2019 ÷ courses 2020

Solution: The result presents the rows which are in relation courses 2020, but not
in courses 2019. Hence, the correct statement is:
courses 2020 − courses 2019

Page 20
15. Consider the relational schema given in Figure 12.

Figure 12: Hall Booking Relational Schema

Find the names of ALL halls that have been booked at least once by a department in
the month of February. [ MSQ: 4 points]
⃝ SELECT hallName FROM hallsMaster
WHERE hallID NOT IN (SELECT hallID FROM hallBooking
WHERE monthBooking = ‘Feb’);
⃝ SELECT hallName FROM hallsMaster
WHERE hallID = (SELECT hallID FROM hallBooking
WHERE monthBooking = ‘Feb’);

SELECT hallName FROM hallsMaster
WHERE hallID IN (SELECT hallID FROM hallBooking
WHERE monthBooking = ‘Feb’);

SELECT hallName FROM hallsMaster
WHERE hallID = ANY (SELECT hallID FROM hallBooking
WHERE monthBooking = ‘Feb’);

Solution: In option 1, NOT IN filters out all rows with month of booking as February.
In option 2, = symbol returns only one department that satisfies the condition.
Options 3 and 4 return all rows that satisfy the given condition.

Page 21
16. Consider the relational schema given in Figure 13.

Figure 13: Employee Schema

If the relations employee, designation and department have 100, 6, 5 rows respec-
tively, what is the maximum number of rows returned by the following query?

[NAT: 4 points]

SELECT * FROM employee FULL OUTER JOIN designation


ON employee.desgID = designation.desgID;

Answer: 105

Solution: desgID is the foreign key in table employee that references designation
table. It follows that the desgID in any row of employee table will have a corre-
sponding entry in the designation table. However, the converse is not always true.
That is, corresponding to each desgID in the designation table, there need not be
an entry in the employee table. Hence, the minimum number of rows in the outer
join is the number of rows in the employee table, which is 100. However, the maxi-
mum may not be 100 because, there could be rows in the designation table that do
not have a matching entry in the employee table. Note that there should be at least
one desgID in department table that has a matching entry in the employee table
since desgID in employee table is a foreign key. If we assume all 100 rows in the
employee table have the same desgID, then there will be five rows from designation
table that do not have matching entries in the employee table, but will appear in the
output of the outer join. Therefore, the maximum number of rows returned by the
given query is 100 + 5 = 105.

Page 22
Consider the following schema, and answer the questions 17.
Students(sid, sname, age, department)
Books(bid, bname, author)
Book Issue(sid, bid, date)

17. Which of the following queries is/are equivalent to the statement given below?
[ MSQ:4 Points]

• Find the names of students who have issued a book named ‘Introduction to SQL’.


{P |∃S ∈ Students ∃I ∈ Book Issue(I.sid = S.sid ∧ P.sname = S.sname ∧
∃B ∈ Books(B.bid = I.bid ∧ B.bname =‘Introduction to SQL’))}
⃝ {∃P |S ∈ Students, I ∈ Book Issue, B ∈ Books(I.sid = S.sid ∧ B.bid =
I.bid ∧ B.Author =‘Introduction to SQL’∧P.sname = S.sname)}

{P |∃S ∈ Students ∃I ∈ Book Issue ∃B ∈ Books(I.sid = S.sid ∧ B.bid =
I.bid ∧ B.bname =‘Introduction to SQL’∧P.sname = S.sname)}
⃝ {P |∃S ∈ Students ∃B ∈ Books(B.bid = S.sid ∧ P.sname = S.sname ∧
B.author =‘Introduction to SQL’))}

Solution: Here we have to find the sname from Students table who have issued a
book having author name ‘Introduction to SQL‘. So, we need to perform natural
join operation between Students, Books and Book Issue table.
The correct TRC query is
{P |∃S ∈ Students ∃I ∈ Book Issue ∃B ∈ Books(I.sid = S.sid ∧ B.bid = I.bid ∧
B.bname =‘Introduction to SQL’∧P.sname = S.sname)}

The above TRC query is equivalent to

{P |∃S ∈ Students ∃I ∈ Book Issue(I.sid = S.sid ∧ P.sname = S.sname ∧ ∃B ∈


Books(B.bid = I.bid ∧ B.bname =‘Introduction to SQL’))}

Thus, option 1 and 3 are correct.

Page 23

You might also like