Week 2 Solution
Week 2 Solution
Total Marks : 20
July 9, 2023
Question 1
Consider two relations StyleName and PrintStyle as follows:
StyleName PrintStyle
Element Style Element Color
Flower Floral Square Blue
Square Block Lines Multi
An operation Θ between StyleName and PrintStyle will generate the following output:
Style Print
Element Style Color
Flower Floral NULL
Square Block Blue
NULL Lines Multi
a) natural join
Answer: d)
Explanation: For natural join, none of the tuples 1 and 3 would not be present in the output.
For left or right outer join, one of the tuples 1 and 3 would not be present in the output. Only
in full outer join all 3 tuples will be present in the output.
Hence, option d) is correct.
1
Question 2
Consider the following CREATE statements: Marks: 2 MCQ
a) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will not be deleted.
b) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will also be deleted.
c) If a faculty id value is deleted from the faculty table, the foreign key constraint will become
invalid.
d) If a faculty id value is deleted from the faculty table, the corresponding records in the
course table that use this faculty id will be deleted and the foreign key constraint will
become invalid.
Answer: a)
Explanation: ON DELETE RESTRICT clause deletes the corresponding records in the parent
table only. Hence, option (a) is correct.
2
Question 3
Consider the following schema:
Identify the correct option(s) in the following to delete all rows from loan table.
Marks: 2 MSQ
Answer: b), d)
Explanation: To delete all rows from a table we can use either DELETE or TRUNCATE command
and the syntax for these commands are:
3
Question 4
Consider the following instance of the relation
BIDDINGTAB(PRODUCTID, HIGHESTBID, LOWESTBID, WINNER, BIDDERS)
a) 0
b) 2
c) 3
d) 5
Answer: a)
Explanation: The average of HIGHESTBID from the given instance is 56000. Thus, SELECT
WINNER FROM BIDDINGTAB WHERE HIGHESTBID<=( SELECT AVG(HIGHESTBID) FROM BIDDINGTAB)
WINNER
Chris L.
results in 3 tuples . However, none of the WINNER’s name is ‘ L.’. Thus the in-
Amara D.
John L.
tersection of the two conditions in the query produces 0 tuples. Hence, option (a) is correct.
4
Question 5
Consider the following instance of the relation
BIDDINGTAB(PRODUCTID, HIGHESTBID, LOWESTBID, WINNER, BIDDERS)
Answer: b)
Explanation: Based on the given SQL Query, the following will be the output
MAX(BIDDERS) WINNER
25 Lewis F.H
7 John L.
10 Chris L.
50 Amara D.
Hence, option (b) is the correct option.
5
Question 6
Consider the following instance of the relational schema PAYSCALE(POSITION, BASE SALARY,
EXPERIENCE)
POSITION BASE SALARY EXPERIENCE
MANAGER 75000 1
MANAGER 90000 5
CLERK 35000 5
DEVELOPER 50000 3
DEVELOPER 70000 5
SCIENTIST 90000 2
Which POSITION will NOT be present in the output generated by the following SQL Query?
SELECT DISTINCT(POSITION)
FROM PAYSCALE
WHERE BASE SALARY<SOME(
SELECT AVG(BASE SALARY)
FROM PAYSCALE
GROUP BY EXPERIENCE); Marks: 2 MCQ
a) CLERK
b) DEVELOPER
c) SCIENTIST
d) MANAGER
Answer: c)
Explanation: As per the syntax and semantics of SQL Queries. Refer to Week 2, slide 8.11.
Hence, option (c) is correct.
6
Question 7
A role Manager has the privilege to perform select, insert, update and delete operations on all
tables of database. A new role Software Engineer is created and the following statement is
executed.
a) Only select
Answer: d)
Explanation: All the privileges of the role of Manager transferred to Software Engineer.
7
Question 8
Consider the following instance of MountainDetails(MountainName,Altitude,StateName)
relation. Marks: 2 MCQ
MountainDetails
MountainName Altitude StateName
Kangchenjunga 8586 Sikkim
Nanda Devi 7816 Uttarakhand
Trisul 7120 Uttarakhand
Kamet 7756 Uttarakhand
Sandakfu 3636 West Bengal
Saltoro Kangri 7742 Jammu and Kashmir
Reo Purgyill 7742 Himachal Pradesh
MountainDetails
MountainName Altitude StateName
Kangchenjunga 8586 Sikkim
Nanda Devi 7816 Uttarakhand
Trisul 7120 Uttarakhand
Kamet 7756 Uttarakhand
Answer: a)
Explanation: Output table containing tuples whose StateName is either Sikkim or Uttarak-
hand. The IN operator allows to specify multiple values in a WHERE clause
Hence, option a) is correct.
8
Question 9
Consider the given relational schema: MountainDetails(MountainName, Altitude, StateName)
Marks: 2 MCQ
Identify the correct SQL command that updates the Altitude by 5% for all records whose
StateName ends with character ‘d’.
a) UPDATE MountainDetails
OF Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d’;
b) UPDATE MountainDetails
SET Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d’;
c) UPDATE MountainDetails
AS Altitude=Altitude*1.05
FROM MountainDetails
WHERE StateName LIKE ‘%d’;
d) UPDATE MountainDetails
SET Altitude=Altitude*1.05
WHERE StateName LIKE ‘%d%’;
Answer: b)
Explanation: As per SQL syntax, LIKE ‘%d’ matches StateName having last character as
‘d’. The percent sign represents zero, one, or multiple characters.
The underscore sign ( ) represents one, single character.
General syntax for upadte statement is:
UPDATE Tablename
SET column1 = value1, column2 = value2, ...
WHERE condition;
9
Question 10
Consider the given relational schema: MountainDetails(MountainName, Altitude, StateName)
Marks: 2 MCQ
Identify the correct statement to find the MountainName, Altitude whose Altitude is greater
than or equal to the average Altitude of all Mountains or Altitude in between 6500 and 8000.
Answer: c)
Explanation: The BETWEEN operator selects values within a given range. The values can be
numbers, text, or dates and begin and end values are included. AVG(Altitude) is used to
calculate average altitude of all mountains
Hence, option c) is correct.
10