Deebo 24007 Awsm: CS315: Principles of Database Systems, IIT Kanpur (23 Aug 2024) Name Roll No Dept
Deebo 24007 Awsm: CS315: Principles of Database Systems, IIT Kanpur (23 Aug 2024) Name Roll No Dept
Instructions:
1. This question paper contains 1 page (2 sides of paper). Please verify.
2. Write your name, roll number, department above in block letters neatly with ink.
3. Write your final answers neatly with a blue/black pen. Pencil marks may get smudged.
4. Don’t overwrite/scratch answers especially in MCQ – ambiguous cases may get 0 marks.
5. Hardcoding attempts will not get any credit.
6. Be extremely precise in your answers and be careful not to make spelling or punctuation mistakes. We may
type your answers as SQLite queries to actual DB and give marks based on how correct the retrieved results are.
The gaana database designed by our DB engineers Deebo and Deeba has 3 tables artist, album and song.
song.length is always a strictly positive integer. artist.aadhar_no is the artist’s Aadhar number and is
unique for every artist. album.id is a unique number given to every album by the music industry. An artist will
never release two albums with the same name, but albums by two different artists may have the same name. An
album will never contain two songs of the same name, but
artist
two different albums may contain songs with same name.
aadhar_no first_name last_name
2011-21 Teebo Totter song
name album_id length
1002-12 Melbo null name album_id length
Cun Cun 104 101
1911-11 Beeba Bopper Buk Buk 101 22
PoorPoor 105 11
1011-11 Kopi null Bok Bok 101 33
PaarPaar 105 2
9022-92 Ceebo Carnum Bak Bak 101 100
Tyt Tyt 106 56
album MunMun 102 25
Tot Tot 106 333
id album_title artist_id release_year Min Min 102 1
Tet Tet 106 222
101 B-Smash 1911-11 2024 MonMon 102 45
Tyt Tyt 107 99
102 M-Swing 1002-12 2022 Kob Kob 103 22
Tut Tut 107 2
103 B-Smash 1011-11 2024 Kub Kub 103 88
Tot Tot 107 42
104 C-Drow 9022-92 2022 Can Can 104 33
Tat Tat 107 111
105 A-Par 1011-11 2023 Con Con 104 55
106 Zing-T 2011-21 2023
107 T-Zing 2011-21 2023
Q1. Write an SQL query to help Deebo count the number of songs of length ≥ 100. (1 mark)
SELECT COUNT(*) FROM song WHERE length >= 100;
Alternatives such as using COUNT(name) are admissible (will receive full marks) but are riskier
in case the name column is NULL in certain rows.
Q2. Write a query to retrieve the Aadhar numbers of all artists without a last name. (2 marks)
SELECT aadhar_no FROM artist WHERE last_name IS NULL;
Please note that using the predicate “last_name = NULL” will not give intended results and such
solutions will receive only partial marks. The NULL value cannot be compared with using usual
comparison operators such as <> or = or !=
Page 2 of 2
Q3. (Foreign Relations) Deeba suspects certain columns might be foreign keys. Given are some
column names. If a column should be a foreign key, write the table and column it should reference
(i.e., its parent). If it shouldn’t be a foreign key, write “None” (don’t just leave blank). (4 marks)
Child Table.Column Parent Table Parent Column
song.album_id album Id
Q6. Write a query to get aadhar_no and first_name of artists who have at least one song of
length ≥ 100. Artist details should not repeat if they have released multiple such songs.(5 marks)
It is possible to solve this problem in several ways e.g., using (correlated) nested queries.
However, simple joins (implicit or explicit) will also do the job and may be much faster.
SELECT aadhar_no, first_name
FROM artist, album, song
WHERE song.length >= 100
AND song.album_id = album.id
AND album.artist_id = artist.aadhar_no
GROUP BY artist.aadhar_no;