DBMS Assignment Week 2
DBMS Assignment Week 2
Total Marks : 20
Question 1
Consider the following instance:
books
genre title author theme
horror The haunting Steve K forest horror
comedy Echoing Laughters Charles G friends comedy
comedy Happiens Carl parody
lifestyle CookBook Julien S Recipes
lifestyle CookBook Julien S Recipes
thriller The Cause Julien S Treasure Mystery
a) The Cause
b) Happiens
c) Echoing Laughters
d) The haunting
Answer: b)
Explanation: The clause ORDER BY theme DESC sorts the tuples in descending alphabetical
order of theme.
Hence, the theme parody will come before friends comedy.
The clause SELECT title, author FROM books WHERE theme LIKE "%y" AND genre NOT LIKE
"%r" projects the tuples <Happiens,Carl>, <Echoing Laughters, Charles G>.
Based on the sorted order, Happiens associated with the theme parody will appear first among
the two tuples.
Hence, option (b) is correct.
1
Question 2
Consider the following instance:
books
genre title author theme
horror The haunting Steve K forest horror
comedy Echoing Laughters Charles G friends comedy
comedy Happiens Carl parody
lifestyle CookBook Julien S Recipes
lifestyle CookBook Julien S Recipes
thriller The Cause Julien S Treasure Mystery
a) 3
b) 4
c) 5
d) 6
Answer: c)
Explanation: CREATE VIEW THEMEVIEW AS SELECT theme FROM books WHERE author LIKE
"% %" selects all themes associated with an author’s name where there is a space.
SELECT COUNT(*) FROM THEMEVIEW produces 5 as output, as all the tuples (even those with
non-distinct values) are counted.
Hence, option (c) is correct.
2
Question 3
Consider the following instance:
scoreboard
gameID TeamName Score Day
1 RacerLeague 87 1
1 HeroZ 12 1
2 HeroZ 42 2
2 Legend21 72 2
3 Legend21 90 1
Which is the correct option to change the value of gameID from 3 to 2? Marks: 2 MCQ
Answer: a)
Explanation: According to the syntax of SQL queries, option (a) is correct.
3
Question 4
Consider the following instance:
scoreboard
gameID TeamName Score Day
1 RacerLeague 87 1
1 HeroZ 12 1
2 HeroZ 42 2
2 Legend21 72 2
2 Legend21 90 1
The query
‘‘SELECT X , AVG(Score) FROM scoreboard GROUP BY X "
produces the following tuples as output:
1 63
2 57
a) gameID
b) gameID, Day
c) Day
d) Day, Score
Answer: c)
Explanation: The Day-wise average of Scores produces 63 on Day 1 and 57 on Day 2. Hence,
option (c) is correct.
4
Question 5
Consider the following two tables:
Product
Supplier
p id p name sup id
sup id sup name sup city
6 Cheez-It 15
18 Order All Boston
2 BN Biscuit 15
15 Jack Hill Ltd London
3 Mighty Munch 16
16 Akas Foods Delhi
5 Jaffa Cakes 18
17 Foodies. London
7 Salt n Shake 17
19 sip-n-Bite. New York
8 Marie Biscuit 20
An operation on these two tables generates the following output. Identify the correct operation.
Marks: 2 MCQ
output
sup id sup name sup city p id p name
18 Order All Boston 5 Jaffa Cakes
15 Jack Hill Ltd London 6 Cheez-It
15 Jack Hill Ltd London 2 BN Biscuit
16 Akas Foods Delhi 3 Mighty Munch
17 Foodies. London 7 Salt n shake
19 sip-n-Bite. New York
Answer: a)
Explanation: In this question the left relation is Supplier and the right relation is Product.
The operation cannot be Natural JOIN or RIGHT OUTER JOIN as the last tuple of Supplier
(for which the value of the common attribute of the Supplier does not match with any value
of Product is present in the output.
When a NATURAL LEFT OUTER JOIN is applied, firstly the tuples are selected from both
left and right relations which have the same sup id. Hence, we get 1 record each of sup id =
16, 17, 18 and 2 records for sup id = 15.
Secondly, the remaining tuples from the left relation which did not have same sup id with
the right relation are also added to the resulting relation output as shown in the last row of
output.
Hence, option (a) is correct.
5
Question 6
Consider the following schema:
player(p id, tournament code, month, match count)
In the player schema, p id uniquely identifies every record. Marks:2 MCQ
Given that a player cannot play more than 5 matches in a month for a tournament, identify
the correct CHECK constraint for the create query of this table.
b) CONSTRAINT CK mat count for CHECK (if match count < 6 is true)
Answer: d)
Explanation: As per the syntax and semantics of SQL notation.
6
Question 7
Consider the following schema:
Football Club(fc code, fc name, fc address)
Player(p id, name, dob, match count, fc code)
You want to design the Player table in such a way that if a fc code value needs to be deleted
from the Football Club table, the corresponding records in the Player table that use this
fc code will also be deleted.
Identify the correct CREATE statement(s) for the Player table from the following.
Marks: 2 MCQ
Answer: a)
Explanation: SQL allows three different types of the definitions of the foreign key:
• ON DELETE CASCADE: When a referenced parent table row is removed, all the children
are removed automatically.
7
• ON DELETE SET NULL: When referenced data in the parent key is deleted, all rows in the
child table that depend on those parent key values have their foreign keys set to null.
8
Question 8
Consider the following instance of the relation BookDetails.
BookDetails (BOOK ID, YEAR PUB, BOOK TITLE, AUTHOR NAME, TOTAL SOLD COPIES)
Marks: 2 MSQ
BookDetails
BOOK ID YEAR PUB BOOK TITLE AUTHOR NAME TOTAL SOLD COPIES
1001 2010 DBMS KORTH 15000
1002 2010 OPERATING SYSTEM GALVIN 25000
1003 2020 COMPILER ULLMAN 12000
1004 1995 DATA STRUCTURES CORMEN 20000
1005 1995 DATA STRUCTURES ULLMAN 20000
1006 1990 COMPUTER NETWORKS FOROUZAN 15000
1007 2010 MACHINE LEARNING MITCHELL 18000
Identify the correct statement(s) to get the following output:
BookDetails
BOOK ID YEAR PUB BOOK TITLE AUTHOR NAME TOTAL SOLD COPIES
1001 2010 DBMS KORTH 15000
1002 2010 OPERATING SYSTEM GALVIN 25000
1003 2020 COMPILER ULLMAN 12000
1005 1995 DATA STRUCTURES ULLMAN 20000
1007 2010 MACHINE LEARNING MITCHELL 18000
9
Question 9
Consider the following instance of the relation BookDetails.
BookDetails (BOOK ID, YEAR PUB, BOOK TITLE, AUTHOR NAME, TOTAL SOLD COPIES)
Marks: 2 MCQ
BookDetails
BOOK ID YEAR PUB BOOK TITLE AUTHOR NAME TOTAL SOLD COPIES
1001 2010 DBMS KORTH 15000
1002 2010 OPERATING SYSTEM GALVIN 25000
1003 2020 COMPILER ULLMAN 12000
1004 1995 DATA STRUCTURES CORMEN 20000
1005 1995 DATA STRUCTURES ULLMAN 20000
1006 1990 COMPUTER NETWORKS FOROUZAN 15000
1007 2010 MACHINE LEARNING MITCHELL 18000
Identify the correct SQL command to find the BOOK ID with BOOK TITLE of BookDetails
whose AUTHOR NAME is neither ‘ULLMAN’ nor ‘KORTH’ and have TOTAL SOLD COPIES is atleast
18000.
Answer: b)
Explanation: BETWEEN operator selects values within a given range. The values can be
text, date, or numbers.
IN operator allows you to easily test if the expression matches any value in the list of values.
It is used to remove the need of multiple OR condition.
Hence, we have used NOT IN to exclude that matches and have TOTAL SOLD COPIES atleast
18000 means TOTAL SOLD COPIES >= 18000.
Hence, option b) is correct and the rest are incorrect.
10
Question 10
Consider the following relation schema:
BookDetails(BOOK ID, YEAR PUB, BOOK TITLE, AUTHOR NAME, TOTAL SOLD COPIES).
Marks: 2 MCQ
Identify the correct statement to create an INDEX on BOOK ID and BOOK TITLE of BookDetails
relation named as ‘Books’.
Answer: b)
Explanation: The general syntax to create any INDEX is
11