Professional Documents
Culture Documents
Week-2 Assignment-2 DBMS Soln PDF
Week-2 Assignment-2 DBMS Soln PDF
Total Marks : 20
Question 1
Identify the valid data-types, which can be used in SQL to define the type of data.
Marks: 2 MSQ
a) varchar
b) memo
c) numeric
d) string
Answer: a), c)
Explanation: As per domain types of the SQL
1
Question 2
Consider the employee table:
Create a new employee ‘W-101’, named ‘Ashwin singh’, with 10,00,000 salary for department
‘Wireless’. Identify the appropriate SQL. Marks: 2 MSQ
Answer: c), d)
Explanation: As per the syntax of insert query
2
Question 3
Refer to the following table student. Identify the correct, “Create SQL statement” for this
table. Marks: 2 MSQ
student
id lastname firstname age
19 Rai Ranjan 24
19 Singh Sanjeev 24
20 Roy Sayantani 24
21 Roy Suraj 29
Answer: b), c)
Explanation:
There are two tuples with same attribute in id and lastname in student table. Hence it
can not be used to define a primary key of the student relation. Hence option a) and d) is
invalid.
(firstname, lastname) or (id, lastname) can uniquiely identify each tuple in the student
table. Hence, option b) and c) are valid.
3
Question 4
Refer to the following table student.
student
id lastname firstname courseid
19 Saha Ranjan 24
19 Singha Sanjeev 24
20 Rai Sayantani 24
21 Raha Suraj 29
Consider:
SELECT *
FROM student
WHERE lastname LIKE ’%a’;
What does above SQL statement select from the student table? Marks: 2 MCQ
Answer: a)
Explanation: % -As per the definition of like queries
4
Question 5
Find names of employees with years of experience greater than atleast one employee in the
Accounts department. Identify the correct, “SQL Query” for this statement. Marks: 2 MSQ
a) SELECT name
FROM employee
WHERE years_exp IS GREATER THAN
(SELECT DISTINCT years_exp
FROM employee
WHERE dept_name = ’Accounts’);
c) SELECT name
FROM employee
WHERE years_exp > GREATER (SELECT years_exp
FROM employee
WHERE dept_name = ’Accounts’);
d) SELECT name
FROM employee
WHERE years_exp > SOME
(SELECT years_exp
FROM employee
WHERE dept_name = ’Accounts’);
Answer: b), d)
Explanation: a), and c) are not valid queries as there are no predicates such as IS GREATER
THAN and > GREATER respectively.
b), d) outputs the names of employees with years of experience greater than at least one em-
ployee in the Accounts department. d) is a nested query where the SOME clause ensures that
the years of experience is greater than at least one employee of accounts department.
5
Question 6
Consider the relation schema.
Find the names of cities whose temperature is not in the range of 71 to 89. Marks: 2 MCQ
Answer: d)
Explanation: As per the definition of SELECT and BETWEEN by queries
6
Question 7
The student information in a company is stored in the following relation.
Marks: 2 MCQ
a) The query returns the section in which the average mark of male and female students is
less than the average mark of all the male students in the school.
b) The query returns the section in which the average mark of male students is less than
than the average mark of all the male students in the school.
c) The query returns the section in which the average mark of male students is more than
the average mark of all the male students in the school.
d) The query returns the section in which the average mark of male students is more than
the average mark of all the students in the school.
Answer: d)
Explanation:
In the above query, initially all the tuples with sex = M are selected and then the GROUP BY
clause groups all tuples according to the sections of the records selected. Then, the average
marks for each section is evaluated and compared with average marks of all students of the
school (as computed from the nested query given below)
7
Question 8
Refer to the following CREATE statements and identify the correct statement(s).
Marks: 2 MCQ
a) If a student id value is deleted from the students table, the corresponding records in the
course table that use this student id will not be deleted.
b) If a student id value is deleted from the students table, the corresponding records in the
course table that use this student id will also be deleted.
c) If a student id value is deleted from the students table, the foreign key constraint will
become invalid.
d) If a student id value is deleted from the students table, the corresponding records in the
course table that use this student id will be deleted and the foreign key constraint will
be come invalid.
Answer: a)
Explanation: ON DELETE RESTRICT clause deletes the corresponding records in the parent
table only.
8
Question 9
A role Manager has the privilege of select, insert, update and delete on all tables of database.
A new role Employee is created and the following statement is executed.
a) Only select
Answer: d)
Explanation: All the privileges of the role Manager transferred to Employee
9
Question 10
company
comp id comp name comp city
18 Order All Boston
15 Jack Hill Ltd London
16 Akas Foods Delhi
17 Foodies. London
19 sip-n-Bite. New York
foods
item id item name item unit comp id
6 Cheez-It Pcs 15
2 BN Biscuit Pcs 15
3 Mighty Munch Pcs 16
4 Pot Rice Pcs 15
5 Jaffa Cakes Pcs 18
7 Salt n Shake Pcs 17
8 Marie Biscuit Pcs 20
output
comp id comp name comp city item id item name item unit
18 Order All Boston 5 Jaffa Cakes Pcs
15 Jack Hill Ltd London 6 Cheez-It Pcs
15 Jack Hill Ltd London 2 BN Biscuit Pcs
15 Jack Hill Ltd London 4 Pot Rice Pcs
16 Akas Foods Delhi 3 Mighty Munch Pcs
17 Foodies. London 7 Salt n shake Pcs
19 sip-n-Bite. New York
Answer: a)
Explanation: a) In this question the left relation company and the right relation is foods.
When a NATURAL LEFT OUTER JOIN is applied, firstly the tuples are selected from both
left and right relations which have same comp id. Hence, we get 1 record each of comp id =
16, 17, 18 and 3 records for comp id = 15. Secondly the remaining tuples from left relation
which did not have same comp id with the right relation are also added to the resulting relation
output as shown in last row of output.
b) Similarly for the NATURAL INNER JOIN, the records from left and right relations
which have the same comp id will only be taken into consideration.
10
c) When a NATURAL RIGHT OUTER JOIN is applied, firstly the tuples are selected
from both left and right relations which have same comp id. Hence, we get 1 record each of
comp id = 16, 17, 18 and 3 records for comp id = 15. Secondly the remaining tuples from
right relation which did not have same comp id with the left relation are also added to the
resulting relation output. i.e, (20, null, null, 8, Marie Biscuit, Pcs) tuple is added.
d)When a NATURAL FULL OUTER JOIN is applied, firstly the tuples are selected from
both left and right relations which have same comp id. Secondly, the remaining tuples from
the left as well as right relations are added to the resulting relation output. Hence, two tuples
(19, sip-n-Bite, New york, null, null, null) and (20, null, null, 8, Marie Biscuit, Pcs) are added.
As we can see, the resultant output relation follows a) and not the other options
11