CS331 Final Exam Fall23
CS331 Final Exam Fall23
Subject:
Cohort: Classroom:
INSTRUCTIONS
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Question B) Consider the ERDs (or ER models) 1 to 4 and the RMs (a) to (j) given below.
For each ERD, give a relational model that represents it correctly by adding a checkmark (X) in the corresponding field in the
table below. If an ERD is represented by none of the given RMs, then add a checkmark in the “none” column. [6pts]
Relational Models
ERDs
none (a) (b) (c) (d) (e) (f) (g) (h) (i) (j)
ER Model 1
ER Model 2
ER Model 3
ER Model 4
Question C) The graphical RM below is designed for a sale company. It tracks the customers, invoices, lines, products, and
vendors as well as some eventually existing connections between them. [10pts]
C) Propose a textual RM to the ERD you provided in the previous question. [10pts]
Example of textual representation for a relation Rel
Rel ( attribute 1, attribute 2, …)
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………….
Question B) Write a SQL query that displays the code and description of all products for which the discounted price is less than
the average price of all stored products (not strictly less than). [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………….
Question C) Write a SQL query that displays the vendors’ codes who provide at least two different products. [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………….
Question D) Display the name of the vendor providing the greatest number of different products. [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………
Mediterranean Institute of Technology Final Exam Fall 2023 5/11
…………………………………………………………………………………………………………………………………………
………………………………………………………………………………………………………………………………………….
Question E) Display the vendors’ codes providing more than three different products. [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Question F) Display all the customers and vendors stored in the database. [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Question G) Write a SQL query that updates the database schema to take into consideration the deletion of products
in all related invoices. However, products update does not affect any of the related tables. [5pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
3- Write a relational algebra expression that identifies the invoices including all the products of the database. [4pts]
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………………………………
Question B)
Consider the following relations and the relational algebra expressions below. Your task is to evaluate the expressions and to
draw the resulting schema corresponding to each (from (a) to (d)). [18pts]
…………………………………………………………………………………………………………………
INSERT INTO people(user_id, age, status)
…………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
VALUES ("bcd001", 45, “A”)
…………………………………………………………………………………………………………………
………………………………………………………………………………………………………………..
………………………………………………………………………………………………………… db.people.updateMany(
…………………………………………………………………………………………………………
{ },
…………………………………………………………………………………………………………
………………………………………………………………………………………………………… { $set: { join_date: “mm-dd-yyyy” } }
………………………………………………………………………………………………………… )
………………………………………………………………………………………………………… db.people.find(
…………………………………………………………………………………………………………
{ },
…………………………………………………………………………………………………………
………………………………………………………………………………………………………… { user_id: 1, status: 1 }
…………………………………………………………………………………………………………
)
……………………
SELECT * …………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
FROM people
…………………………………………………………………………………………………………………
WHERE status = "A" …………………………………………………………………………………………………………………
………………………………………………………………………………………………
…………………………………………………………………………………………………………………
SELECT user_id, status …………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
FROM people
…………………………………………………………………………………………………………………
WHERE age > 25 …………………………………………………………………………………………………………………
……………………………………
SELECT * …………………………………………………………………………………………………………………
…………………………………………………………………………………………………………………
FROM people
…………………………………………………………………………………………………………………
WHERE age > 25 …………………………………………………………………………………………………………………
………………………………………………………………………………………………
AND age <= 50
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
………………………………………………………………………………………………………… db.people.find( { status: "A" } ).sort( { user_id: -1 } )
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
db.people.find(
…………………………………………………………………………………………………………
…………………………………………………………………………………………………………
{ age: { $exist: false} } )
………………………………………………………………………………
A. It can easily store unstructured data Statement 1: All NoSQL databases support ACID transactions.
B. It's ACID-compliant Statement 2: NoSQL databases come in a variety of types based on
C. It can enable development in the cloud their data model.
D. All of the above
A. Both statement 1 and statement 2 are true
B. None of the statements is true
C. Only statement 1 is true
D. Only statement 2 is true
3. Which of the following is a characteristic of a NoSQL 8. What is the challenge of using NoSQL databases?
database?
A. Limited scalability
A. Uses tables for storage B. Limited support for unstructured data
B. Needs a schema C. Limited query capabilities
C. Requires JOINs D. None of the above
D. Uses JSON
4. Which of the following is a primary classification for 9. SQL command types include data manipulation language
NoSQL architectures? (DML) and data definition language (DDL).
5. SQL command types include data manipulation language 10. Which one of the following represents “column” in
(DML) and data definition language (DDL). MongoDB __________.
A. True A. Database
B. False B. Field
C. Collection
D. Document
END
Good Luck