0% found this document useful (0 votes)
5 views

Midsem-Soln Dbms

The document contains a midterm exam for a database management systems course. It consists of 4 questions testing knowledge of relational algebra, SQL queries, functional dependencies, and BCNF normalization. The questions involve describing queries, writing results, analyzing functional dependencies and decomposing schemas.

Uploaded by

Pujan Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Midsem-Soln Dbms

The document contains a midterm exam for a database management systems course. It consists of 4 questions testing knowledge of relational algebra, SQL queries, functional dependencies, and BCNF normalization. The questions involve describing queries, writing results, analyzing functional dependencies and decomposing schemas.

Uploaded by

Pujan Shah
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CS 245, Database Management Systems

Midsem Exam, Winter 2022-2023


Department of Computer Science and Engineering
IIT Guwahati
Time: Two hours

Note: For Q1 and Q2 refer to the tables shown in Figure 1 at the end of the paper. Note
that the tables extend from page 6 to page 9 and some of the tables span two pages.
The list of tables is as follows: instructor, student, department, course, teaches,
takes, advisor and prereq. Their meaning is the same as in the lectures.
1. First describe in English each of following relational algebra queries. Then write down
the relation returned by each query for the tables in Figure 1.
(a)
Πdept name (instructor

ΠID,name,dept name,instructor.salary (instructor
./instructor.salary > R.salary ρR (Πsalary (instructor))))

(5)

Solution: Find the departments which instructors with the least salary belong
to.

dept name
Music

(b)
Πstudent.ID,student.name (student
./ takes
./ Πcourse id,sec id,semester,year (σname=”Einstein” (instructor ./ teaches)))

(5)

Solution: Find the IDs and names of students who have taken a course section
taught by Einstein.

ID name
44553 Peltier

(c)
ΠID,name (instructor
./ID=R.i ID
ΠR.i ID (ρR (advisor) ./R.i ID = S.i ID ∧ R.s ID 6= S.s ID (ρS (advisor))))
CS 245 Midsem (Cont.) Winter 2022-23 Page 2 of 9

(5)

Solution: Find the IDs and names of instructors who are advisors for more
than one student.

ID name
22222 Einstein
98345 Kim
45565 Katz

(d)

ΠID,name (student
./student.ID=takes.ID takes
./takes.course ID=course.course ID (σdept name = ”Biology” (course)))

(5)

Solution: Find the IDs and names of students who have taken at least one course
offered by the Biology Department.

ID name
98988 Tanaka

2. First describe in English each of following SQL queries. Then write down the relation
returned by each query for the tables in Figure 1.
(a)
s e l e c t dept name
from instructor
where s a l a r y > ( s e l e c t avg ( s a l a r y )
from instructor
where dept name = ’Comp . S c i . ’ )

(5)

Solution: Find all departments which have at least one instructor with salary
greater than the average salary in the CS department.
CS 245 Midsem (Cont.) Winter 2022-23 Page 3 of 9

dept name
Finance
Physics
Physics
Finance
Comp. Sci.
Elec. Eng.

(b)
s e l e c t dept name , count ( d i s t i n c t ID ) as i n s t r c o u n t
from instructor n a t u r a l j o i n teaches
where s e m e s t e r =’ Spring ’ and y e a r =2010
group by dept name ;

(5)

Solution: Find the number of instructors in each department who teach a


course in the Spring 2010 semester.

dept name instr count


Comp. Sci. 3
Finance 1
History 1
Music 1

(c)
s e l e c t dept name , count ( d i s t i n c t ID ) from instructor
where s a l a r y > 50000
group by dept name ;

(5)

Solution: List the department names along with the number of faculty in the
department who earn more than 50000.
CS 245 Midsem (Cont.) Winter 2022-23 Page 4 of 9

dept name count(distinct ID)


Biology 1
Comp. Sci. 3
Elec. Eng. 1
Finance 2
History 2
Physics 2

(d)
s e l e c t count ( d i s t i n c t ID )
from takes
where ( c o u r s e i d , s e c i d , s e m e s t e r , y e a r ) i n
( s e l e c t course id , s e c i d , semester , year
from teaches
where teaches . ID= 1 0 1 0 1 ) ;

(5)

Solution: Find the total number of distinct students who have taken course
sections taught by the instructor with ID 10101.

count(distinct ID)
6

3. Consider the following set F of functional dependencies for the relation schema R =
(A, B, C, D, E):

A → BC
CD → E
B→D
E→A

(a) List all the functional dependencies in F + of the form α → β, where α has a single
attribute and α ∩ β = ∅. (You can write X → Y Z instead of X → Y and X → Z,
and so on.)
(5)
CS 245 Midsem (Cont.) Winter 2022-23 Page 5 of 9

Solution: A → BCDE, B → D, E → ABCD

(b) List all the candidate keys for R.


(5)

Solution: A, E, BC, CD.

(c) Consider the decomposition of the above schema R into R1 = (A, B, C) and R2 =
(A, D, E). Is this a lossless decomposition? Justify your answer.
(5)

Solution: The decomposition is lossless since R1 ∩ R2 = A, and A → R1 is in


F +.

(d) Consider the same decomposition of R as above into R1 = (A, B, C) and R2 =


(A, D, E). Is this decomposition dependency-preserving? Justify your answer.
(5)

Solution: The decomposition is not dependency preserving, since the depen-


dency CD → E in F + can only be checked by checking both the relations. The
same is true for the dependency B → D in F + .

4. Consider the relation schema R(A, B, C, D) with the set F of functional dependencies

AB → C
C→D
D→A

(a) Find all the BCNF violations, if any, for the schema R by the functional dependen-
cies in F + .
(5)

Solution: The set of superkeys for R with respect to F is


{AB, BC, BD, ABC, BCD, ABCD}. The functional dependencies in F +
CS 245 Midsem (Cont.) Winter 2022-23 Page 6 of 9

that violate the BCNF condition for R are

C→D
D→A
C→A
CD → A
AC → D
AC → AD
CD → AC
AC → CD

Note that no trivial dependency (i.e., α → β with β ⊆ α) can violate the BCNF
condition.

(b) Decompose the schema R, if necessary, into a collection of schemas each of which
is in BCNF. Write only the final answer. Do not show the intermediate steps.
(5)

Solution: The possible solutions are R = (R1 , R2 , R3 ) where the choices for
R1 , R2 , R3 are:

R1 = (C, D), R2 = (A, C), R3 = (B, C)


R1 = (A, D), R2 = (C, D), R3 = (B, C)

Note that a decomposition can be listed in any order. For this example, it can
be shown that any schema in the decomposition cannot have more than two
attributes.
CS 245 Midsem (Cont.) Winter 2022-23 Page 7 of 9

Figure 1: Tables for Q1 and Q2

instructor

ID name dept name salary


−−−−− −−−−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−−−−−− −−−−−−−−−−
10101 Srinivasan Comp . S c i . 65000.00
12121 Wu Finance 90000.00
15151 Mozart Music 40000.00
22222 Einstein Physics 95000.00
32343 El Said History 60000.00
33456 Gold Physics 87000.00
45565 Katz Comp . S c i . 75000.00
58583 Califieri History 62000.00
76543 Singh Finance 80000.00
76766 Crick Biology 72000.00
83821 Brandt Comp . S c i . 92000.00
98345 Kim E l e c . Eng . 80000.00

student

ID name dept name tot cred


−−−−− −−−−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−−−−−−− −−−−−−−−
00128 Zhang Comp . S c i . 102
12345 Shankar Comp . S c i . 32
19991 Brandt History 80
23121 Chavez Finance 110
44553 Peltier Physics 56
45678 Levy Physics 46
54321 Williams Comp . S c i . 54
55739 Sanchez Music 38
70557 Snow Physics 0
76543 Brown Comp . S c i . 58
76653 Aoi E l e c . Eng . 60
98765 Bourikas E l e c . Eng . 98
98988 Tanaka Biology 120

department

dept name building budget


CS 245 Midsem (Cont.) Winter 2022-23 Page 8 of 9

−−−−−−−−−−−−−−−−−−−− −−−−−−−−−−−−−−− −−−−−−−−−−−−−−


Biology Watson 90000.00
Comp . S c i . Taylor 100000.00
E l e c . Eng . Taylor 85000.00
Finance Painter 120000.00
History Painter 50000.00
Music Packard 80000.00
Physics Watson 70000.00

course

course id title dept name c r e d i t s


−−−−−−−−− −−−−−−−−−−−−−−−−−−−−−−−−−−−−−− −−−−−−−−−− −−−−−−−
BIO−101 Intro . to Biology Biology 4
BIO−301 Genetics Biology 4
BIO−399 Computational B i o l o g y Biology 3
CS−101 I n t r o . t o Computer S c i e n c e Comp . S c i . 4
CS−190 Game Design Comp . S c i . 4
CS−315 Robotics Comp . S c i . 3
CS−319 Image P r o c e s s i n g Comp . S c i . 3
CS−347 Database System Concepts Comp . S c i . 3
EE−181 I n t r o . t o D i g i t a l Systems E l e c . Eng . 3
FIN−201 Investment Banking Finance 3
HIS−351 World H i s t o r y History 3
MU−199 Music Video P r o d u c t i o n Music 3
PHY−101 Physical Principles Physics 4

teaches

ID course id sec id semester year


−−−−− −−−−−−−−− −−−−−−−− −−−−−−−− −−−−−−
10101 CS−101 1 Fall 2009
10101 CS−315 1 Spring 2010
10101 CS−347 1 Fall 2009
12121 FIN−201 1 Spring 2010
15151 MU−199 1 Spring 2010
22222 PHY−101 1 Fall 2009
32343 HIS−351 1 Spring 2010
45565 CS−101 1 Spring 2010
45565 CS−319 1 Spring 2010
76766 BIO−101 1 Summer 2009
CS 245 Midsem (Cont.) Winter 2022-23 Page 9 of 9

76766 BIO−301 1 Summer 2010


83821 CS−190 1 Spring 2009
83821 CS−190 2 Spring 2009
83821 CS−319 2 Spring 2010
98345 EE−181 1 Spring 2009

takes

ID course id sec id semester year grade


−−−−− −−−−−−−−− −−−−−−−− −−−−−−−− −−−−−− −−−−−
00128 CS−101 1 Fall 2009 A
00128 CS−347 1 Fall 2009 A−
12345 CS−101 1 Fall 2009 C
12345 CS−190 2 Spring 2009 A
12345 CS−315 1 Spring 2010 A
12345 CS−347 1 Fall 2009 A
19991 HIS−351 1 Spring 2010 B
23121 FIN−201 1 Spring 2010 C+
44553 PHY−101 1 Fall 2009 B−
45678 CS−101 1 Fall 2009 F
45678 CS−101 1 Spring 2010 B+
45678 CS−319 1 Spring 2010 B
54321 CS−101 1 Fall 2009 A−
54321 CS−190 2 Spring 2009 B+
55739 MU−199 1 Spring 2010 A−
76543 CS−101 1 Fall 2009 A
76543 CS−319 2 Spring 2010 A
76653 EE−181 1 Spring 2009 C
98765 CS−101 1 Fall 2009 C−
98765 CS−315 1 Spring 2010 B
98988 BIO−101 1 Summer 2009 A
98988 BIO−301 1 Summer 2010 NULL

advisor

s ID i ID
−−−−− −−−−−
00128 45565
12345 10101
23121 76543
44553 22222
CS 245 Midsem (Cont.) Winter 2022-23 Page 10 of 9

45678 22222
76543 45565
76653 98345
98765 98345
98988 76766

prereq

course id prereq id
−−−−−−−−− −−−−−−−−−
BIO−301 BIO−101
BIO−399 BIO−101
CS−190 CS−101
CS−315 CS−101
CS−319 CS−101
CS−347 CS−101
EE−181 PHY−101

You might also like