0% found this document useful (0 votes)
12 views17 pages

Final Practice2024

The document is a practice final examination for Comp 3150 Winter 2020, administered by Dr. C. I. Ezeife. It consists of two sections: Section A with 15 multiple choice questions worth 30 marks and Section B with 4 questions worth 70 marks, covering topics such as SQL queries, relational algebra, and database normalization. Students must adhere to strict confidentiality and honesty guidelines during the closed book examination.

Uploaded by

dg.xixuan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views17 pages

Final Practice2024

The document is a practice final examination for Comp 3150 Winter 2020, administered by Dr. C. I. Ezeife. It consists of two sections: Section A with 15 multiple choice questions worth 30 marks and Section B with 4 questions worth 70 marks, covering topics such as SQL queries, relational algebra, and database normalization. Students must adhere to strict confidentiality and honesty guidelines during the closed book examination.

Uploaded by

dg.xixuan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Comp 3150 (60-315) Winter 2020

Final Examination (Only for PRACTICE in Fall 2024)


Examiner: Dr. C. I. Ezeife: Given: Thurs., Apr. 9, 2020

Student Name:__________________________________

Student Number:____________________________
________________________________________________________________________
INSTRUCTIONS (Please Read Carefully)
Examination Period is 2 hours 30 minutes
Answer all questions. Write your answers in the spaces provided in the question
paper. This is closed book and closed notes test. WRITE IN PEN or TYPE IN.
Total Marks =100. Total number of sections = 2
Please read questions carefully! Misinterpreting a question intentionally or
unintentionally results in getting a “ZERO” for that question. Good Luck!!!
CONFIDENTIALITY AGREEMENT & STATEMENT OF HONESTY
I confirm that I will keep the content of this assignment/examination confidential.
I confirm that I have not received any unauthorized assistance in preparing for or doing
examination. I confirm knowing that a mark of 0 may be assigned for copied work.
For Online Test/Examination in Comp 3150 Winter 2020: (additional rules to be observed):
1. I confirm that I agree to write this final examination as a closed book examination.
2. I confirm that I am the student with the name and student id signed below.
3. I confirm that I agree to not send email, chat, text or talk in any way to people other than the
instructor or proctoring GA of this course during this examination.
4. I confirm that I agree to not engage in copying or cheating during this online examination.
________________________________________ ________________________________________
Student Signature Student Name (please print)
________________________________________ ________________________________________
Student I.D. Number Date
____________________________________________________________________________________________________________________
For marking purposes only (This part not to be filled by students)
Question Mark
Section A
(30 marks for 15 multiple choice questions) /30
Section B
Que 1 (20 marks)
/20
Que 2 (15 marks)
/20
Que 3 (20 marks)
/20
Que 4 (15 marks)
/10

Total /100

1
Section A
30 marks for 15 Multiple Choice Questions. Each question in this
section is worth 2 marks.
Fig. 1: Music Database: For music performed by musicians: Note genre means class
MUSICIAN
Ssn Mname Genre Age
11 James Adam Pop 24
22 Mary Kata Pop 36
33 Pat Smith Country 19
44 Cathy Good Hip Hop 70

SONG
Stitle Author Minuteslong
Hello World 21 Savage 25
Happy All 21 Savage 32
Love Sosa Chief Keef 40

PERFORMS
Ssn Stitle Hours
11 Hello World 20
11 Happy All 10
22 Hello World 10
22 Happy All 12
33 Hello World 12
33 Happy All 18
33 Love Sosa 15

Use the MUSIC database of Fig 1 to answer the following questions.

1. The result of the relational algebra query


(Mname(σstitle=’Hello World’ (Performs Musician)) is:
A. James Adam

B. Mary Kata

C. James Adam
Mary Kata

D. James Adam
Mary Kata
Pat Smith
E. None of the above

2
2. The SQL query to retrieve the average number of hours performed on songs by
musicians from each genre is ____.
A. SELECT genre, avg(hours) from performs group by genre;
B. SELECT p.ssn, m.genre, sum(p.hours) from performs p, musician m where
p.ssn=m.ssn group by p.ssn, m.genre;
C. SELECT m.genre, avg(p.hours) from performs p, musician m where p.ssn=m.ssn
group by m.genre;
D. All of the above
E. None of the above

3. In SQL, to get the song titles of songs performed on by musicians from Pop or Country
genres, use?
A. SELECT Stitle FROM Song where genre = ‘Pop’ or genre = ‘Country’;
B. SELECT Stitle FROM Song, Performs where genre = ‘Pop’ or genre = ‘Country’;
C. SELECT Stitle FROM Song, Performs, Musician where genre = ‘Pop’ or genre =
‘Country’;
D. All of the above
E. None of the above

4. The SQL query for retrieving and presenting unique (not duplicates) musician names
with their age, where only age is in sorted descending order (that is big to small order) is:

A. SELECT distinct(Mname), age FROM MUSICIAN ORDER BY age;


B. SELECT distinct(Mname), age FROM MUSICIAN ORDER BY mname desc;
C. SELECT distinct(Mname), age FROM MUSICIAN ORDER BY age desc;
D. SELECT distinct(Mname), age FROM MUSICIAN ORDER BY mname asc;
E. None of the above

5. With SQL, how can you delete the records where the Hours is 18 from the
PERFORMS Table?

A. DELETE ROW Hours = 18 FROM PERFORMS;


B. DELETE Hours = 18 FROM PERFORMS;
C. DELETE FROM PERFORMS WHERE Hours = 18;
D. REMOVE Hours = 18 FROM PERFORMS;
E. None of the above

3
Fig. 1: Music Database: For music performed by musicians: Note genre means class
MUSICIAN
Ssn Mname Genre Age
11 James Adam Pop 24
22 Mary Kata Pop 36
33 Pat Smith Country 19
44 Cathy Good Hip Hop 70

SONG
Stitle Author Minuteslong
Hello World 21 Savage 25
Happy All 21 Savage 32
Love Sosa Chief Keef 40

PERFORMS
Ssn Stitle Hours
11 Hello World 20
11 Happy All 10
22 Hello World 10
22 Happy All 12
33 Hello World 12
33 Happy All 18
33 Love Sosa 15

Note: MUSIC database of Fig 1 replicated here just for ease of reference.

6. What is retrieved by the following SQL query from Music database?

Select m.Mname from Musician m where NOT EXISTS


(select * from Performs p where p.SSn = m.Ssn and p.Stitle = ‘Hello World’);

A. James Adam
B. Mary Kata
C. Pat Smith
D. Cathy Good
E. None of the above

7. From Fig. 1, the Relational algebra query to retrieve Stitle of all songs performed on
by ‘Mary Kata’ is ____.
A. Stitle (σMname=’Mary Kata’ (Musician))
B. Stitle (σMname=’Mary Kata’ (Performs))
C. Stitle (σMname=’Mary Kata’ (Song))
D. All of the above
E. None of the above

4
8. The result of the following relational calculus query on Fig. 1 database is:
{m.Ssn, m.Mname | Musician(m) and m.age < 40}

A. Mary Kata
Pat Smith
B.
11 James Adam
22 Mary Kata
33 Pat Smith

C. 22 Mary Kata
33 Pat Smith

D. 44 Cathy Good

E. None of the above

9. The following natural join relational algebra query (Performs Musician) is equivalent to:
A. Performs U Musician.
B. Performs x Musician.
C. Performs ∩ Musician
D. σ Project.Dept=Student.Dept Performa.Ssn=Musician.Ssn(Performs x Musician).
E. None of the above

10. Which of the following relational algebra operators require that its operands be type
compatible?

A. Cartesian product
B. Set difference
C. Natural join
D. All of the above
E. None of the above

11. With B-tree Indexes, all data nodes are stored on the leaf nodes.

A. TRUE
B. FALSE
C. NOT APPLICABLE
D. All of the above
E. None of the above

5
12. A secondary index ______:

A. Has its index field the same as the ordered key field in the primary data file.
B. Is the same as a primary index.
C. Has to be a single level index.
D. All of the above
E. None of the above

13. While inserting records in the database, possible integrity constraint violation is:
A. Domain constraint.
B. Entity constraint.
C. Referential integrity constraint.
D. All of the above
E. None of the above

14. The Music database of Fig. 1 is not in 3NF.

A. FALSE.
B. TRUE.
C. MAY BE.
D. All of the above
E. None of the above

15. The Music database of Fig. 1 is in BCNF.

A. FALSE.
B. TRUE.
C. MAY BE.
D. All of the above
E. None of the above

6
Section B (70 marks ):
This section has 4 questions:

Fig. 2: The ER model Diagram for a UNIVERSITY database Database

Name

Consider the ER diagram of Fig 2 for a UNIVERSITY database that is used to keep track of
students' transcripts. This is similar but not identical to the database shown in the Figure 1.2
in the book used in class.

Question 1: (total marks: 20 for 10 + 6 + 4)

a. Define a relational database schema representation for this database system


ER model, clearly defining the table schemas for 6 of the 9 tables for entities
and relationships, with their attributes, identifying their primary keys and
foreign key attributes constraints. Include in your 6 the two tables
College_Attended and Attendance_Record . (10 marks)
b. Write all the SQL instructions to create the 6 of the database tables including
the two tables College_Attended and Attendance_Record with all their primary
and foreign key constraints specified. (6 marks)
c. Write an SQL query for the English query “Print the student name, the college
name, the start date and end date of a student named Pete Adams”.
(4 marks)

7
Solution for Question 1 (20 marks for all of a to c)
Sub questions Answers
a. Relation DB for
Fig 2.

For both Entities


and attributes
(5 marks) in ER

And Relationships
and attributes
(5 marks) in ER

b. creating the 6
tables
(6 marks)

8
c. SQL query
(4 marks)

Question 2: (total marks = 20 for 5 + 5 + 5 + 5)

(i) Consider the universal relation R = {A, B, C, D, E, F} and the set of


functional dependencies in this database is:
FD1: {A, B} -> {C, D, E, F},
FD2: {D} -> {E, F}.

Given that the key for R is {A,B},

a. Is the relation R in 3NF? Explain your answer using functional


dependencies. (2.5 marks)

9
b. Decompose R into 3NF relations specifying the primary keys and
functional dependencies that exist in each of the relations and thus, in the
database. (5 marks)

(ii) Given the STUDENT record relation schema:

STUDENT(Studentid, Courseid, Studentname, Course_grade)

Assume that a student may take multiple courses and that percentage grade is
entered. The primary key is (Studentid, Courseid). Other dependencies may exist
from the meaning of this domain.

a. Is the relation STUDENT in 3NF? Explain your answer using functional


dependencies. (2.5 marks)
b. Normalize the relation STUDENT into 3NF set of relations if not in 3NF,
showing your new normalized database with its functional dependencies.
(5 marks)
Que 2 (20 marks for all of (i) a, b and (ii) a, b)
(i) (a) Is R in 3NF ?
(5 marks)

(b) Decompose R
into 3NF. Show FDs.
(5 marks)

10
(ii) (a) Is STUDENT in
3NF?
(5 marks)

(b) Normalize
STUDENT. Show
FDs.
(5 marks)

11
Fig 3: An Instance of a COMPANY relational Database

12
Question 3: (total marks = 20 for 10 + 10)

Using the COMPANY database of Fig 3, answer the following questions


by expressing the queries in:
(i) SQL,
(ii) Relational algebra,
(iii) Relational Calculus as well as showing the,
(iv) result of each query. Note: specify any needed aggregate function or group
by attributes within your relational calculus and algebra queries appropriately.

(a) Retrieve the names of male employees who work on project with id 2 and who
also have a male dependent. (10 marks)

(b For each project, list the project name and the minimum hours per week (by all
employees) spent on that project. For example, the minimum hours on project 30
(Newbenefits) is 5. (10 marks)

** Some symbols that may be useful for copying are: σ, ,  ,

Que 3 (10 marks for each of a and b )


(a) Query in (a) Retrieve the names of male employees who work on project
SQL, with id 2 and who also have a male dependent.
Relational SQL:
Algebra,
Relational
Calculus,
Result
(10 marks)

Relation Algebra:

Relational Calculus:

13
Query Result:

(b) Query in (b) For each project, list the project name and the minimum hours per week
SQL, (by all employees) spent on that project.
Relational
Algebra,
Relational
Calculus,
Result
(10 marks)

Relational Algebra:

Result:

14
Question 4 : (total marks = 10 for 5 + 5)

(a). Given the following B-tree of order p=3 which has already inserted into it the
values 40, 17, 32, 20, you are required to insert into it, the sequence of ids
31, 99, 43 and show:
(i) the steps for inserting the given sequence of unique ids for some database
records of a relation, and
(ii) the final B-tree index structure of order p=3 (or with maximum of 3 pointers)
after the insertions. B-tree is used for speeding up retrieval of records from their
primary data file stored on disk.

Show the steps through arriving at your final tree before giving your final tree.
(5 marks)
32

17 20 40

For (a): Starting B-tree of order p=3

Solution (a) (5marks)


Give each step of the insertion of 31, 99, 43 into the Starting B-tree with
40, 17, 32, 20 already inserted given above.

Step 1: insert 31 into the above B-tree to get:

Step 2: insert 99 into the above B-tree from step 1 to get:

15
Step 3: insert 43 into the above B-tree from step 2 to get:

This is the final B-tree after inserting 31, 99, 43 into B-tree with 40, 17, 32, 20.

(b). Given the following B+-tree of order p=3 (and p-leaf of 2), which has already
inserted into it the values 40, 17, 32, 20, you are required to insert into it, the
sequence of ids 31, 99, 43 and show:
(i) the steps for inserting the given sequence of unique ids for some database
records of a relation into the B+-tree, and
(ii) the final B+-tree index structure of order p=3 (or with maximum of 3 pointers)
after the insertions. B+-tree is used for speeding up retrieval of records from their
primary data file stored on disk.

Show the steps through arriving at your final tree before giving your final tree.
(5 marks)
20 32

17 20 40
32

For (b): Starting B+-tree of order p=3 (and p-leaf = 2)


Solution (b) (5marks)
Give each step of the insertion of 31, 99, 43 into the Starting B+-tree above with
40, 17, 32, 20 already inserted.

Step 1: The following shows the B+-tree after insertion of 31.

16
Step 2: The following shows the B+-tree after insertion of 99.

Step 3: The following shows the B+-tree after insertion of 43.

This is the final B+-tree after inserting 31, 99, 43 into the B+-tree with 40, 17, 32,
20 already inserted.

17

You might also like