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

A2 (4)

The document outlines Assignment 2 for COMP3278B, focusing on the development of a database for PIX Press's online printing platform. It includes a revised E-R diagram, relational table schema, and specific SQL tasks to create tables, insert data, and execute queries. The assignment is due on April 1st, 2025, and requires submission in a PDF format on Moodle.

Uploaded by

wzy190817
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)
2 views

A2 (4)

The document outlines Assignment 2 for COMP3278B, focusing on the development of a database for PIX Press's online printing platform. It includes a revised E-R diagram, relational table schema, and specific SQL tasks to create tables, insert data, and execute queries. The assignment is due on April 1st, 2025, and requires submission in a PDF format on Moodle.

Uploaded by

wzy190817
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
You are on page 1/ 3

COMP3278B Introduction to Database Management Systems

2024 – 2025

Assignment 2
Due: April 1st 23:59
———————————————————————————————————————
Overview
You have analyzed the requirements of the online printing ordering platform for digital printing firm
PIX Press in assignment 1. The company decided to remove some of the features so that they can
release the platform as soon as possible. Their developers have revised the E-R diagram and
produced a relational table schema with data type assigned. You are contracted to join them in
preparing the database for the system.

Revised E-R diagram


The E-R diagram of the revised system is as follow. Please note that this is different from the
solution to assignment 1.
Relational Table Schema (with data type)

AppUser (user_id: INT, name: VARCHAR(80))


Foreign keys: none
Customer (user_id: INT, birthday: DATE)
Foreign keys: user_id refers AppUser
CustomerPhone (user_id: INT, phone: VARCHAR(80))
Foreign keys: user_id refers Customer
Admin (user_id: INT, supervisor_id: INT)
Foreign keys: user_id refers AppUser, {supervisor_id} refers Admin {user_id}
Gallery (gallery_id: INT, name: VARCHAR(80), creation_date: DATE, user_id: INT)
Foreign keys: user_id refers AppUser
Photo (gallery_id: INT, photo_id: INT, filename: VARCHAR(80))
Foreign keys: gallery_id refers Gallery
Product (product_id: INT, description: TEXT, price: decimal(10,2))
Foreign keys: none
PrintOrder (order_id: INT, user_id: INT, status: VARCHAR(80), pic_id: INT)
Foreign keys: user_id refers Customer, {pic_id} refers Admin {user_id}
Item (order_id: INT, item_id: INT, quantity: INT, product_id: INT,
gallery_id: INT, photo_id: INT)
Foreign keys: order_id refers PrintOrder, product_id refers Product,
{gallery_id, photo_id} refers Photo

Tasks

Study the E-R diagram and the relational table schema. Construct the SQL statements for the
following tasks. Your answer should be executable in the departmental MySQL server, which is
running MySQL version 5.7.42.

1) [20%] Create the tables according to the constraints given, including all primary keys and foreign
keys. Columns that cannot be NULL must be set to NOT NULL. (Submission Requirement: Include
the exact CREATE TABLE statements in your answer.)
2) [20%] Write the SQL query for inserting the necessary data for the following order. (Submission
Requirement: Provide the SQL INSERT statements.)
Order ID 123
Customer David Brook (ID: 10060)
Birthday: November 20, 1989
Phone numbers: 960-0123, 550-1234
PIC Miranda Spears (ID: 9054)
Items Item 1
4x IMG_123.jpg (ID: 6)
from Gallery “Summer 2019” (ID: 7, created on Oct 22, 2019, owned by the
customer)
on product “4R glossy print” (ID: 3, @$1.1)
Status Printing in progress.

3) [60%] Load the data in A2_test_data.sql. For each of the following tasks, give a single SQL query
that provide the result needed. (Submission Requirement: Include the SQL query for each task and
execute the queries and submit a screenshot of the results.)
 Select at least the primary key(s) of all related tables if the columns to be listed is not specified.
 Assume ascending order if ordering direction is not specified.
 Your query must handle all possible scenario according to the given constraint.
 There should not be duplicated results.
 A set of sample data is available on Moodle for your reference. You are suggested to test your
SQL with your own set of data.

a. List all available products in the system ordered by price.


b. Find the user IDs and names of all customers.
c. Find the customer name, phone numbers, and order ID of all orders that has “New” in the
status. If the customer has multiple phone numbers, concatenate them by commas in the result.
(Hint: use GROUP_CONCAT)
d. List all items of order ID 3, showing the item ID, quantity, product description, and the subtotal.
Subtotal equals to the product price times quantity.
e. List all orders by customer with user ID 5, showing the order ID, status, number of items (sum
of quantity), and the total amount.
f. Find the names of all users that is a customer and an admin user.
g. Find all admin users is not a supervisor.
h. List all galleries owned by admin users, in a descending order of the number of photos in the
gallery. If there exist two galleries with the same number of photos, order them in descending
order of the creation date.
i. Find the number of times each of the photos in gallery ID 1 is included in an order. A photo
that is placed in the same order multiple times should be counted as once only. Photos that
have never been ordered must also be shown.
j. Find all customer name of orders that has the greatest number of order items (not considering
quantity).

Submissions
Submit your work in a single PDF file on Moodle before the deadline. Late penalty will be applied
for late submission.

You might also like