0% found this document useful (0 votes)
61 views12 pages

Inft1105 - A3 - S23

This document provides instructions for an assignment to create and query a SQL database. It includes 7 queries to write SQL statements for to retrieve specific data from tables in the CityHockeyAssociation database. The document outlines what should be included in each query and the marking scheme for the assignment.

Uploaded by

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

Inft1105 - A3 - S23

This document provides instructions for an assignment to create and query a SQL database. It includes 7 queries to write SQL statements for to retrieve specific data from tables in the CityHockeyAssociation database. The document outlines what should be included in each query and the marking scheme for the assignment.

Uploaded by

Mini Muni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

This content is protected and may not be shared, uploaded, or distributed.

Introduction to Databases
Assignment #3 - Instructions
BEFORE YOU START ------------------------------------------
Before beginning, be sure to review all of the instructions and the included marking
scheme to make sure you are aware of what you are graded on for this assignment.

FIRST, CREATE THE DATABASE ------------------------------------------


I have included the file ‘inft1105_a3_dbcreation.sql, download it somewhere you won’t lose it.
1. Open SQL Server Management Studio (SSMS) and connect to your SQL Server instance.
2. Create a new database named CityHockeyAssociation.
3. Click Ctrl-O and SSMS should open the ‘Open File’ window. Find the
inft1105_a3_dbcreation.sql and open it. Alternatively, you can drag and drop script files
into SSMS and it will open them.
4. Execute the script. If it fails, check that you named the database correctly.

THE QUERIES ------------------------------------------


Write a single statement for each query requested below. Helpful comments for each
query are worth a mark per query.
Remember to verify the result of your query is the correct result!

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

Week 8 Questions ------------------------------------- SELECT, FROM, ORDER, WHERE, AGGREGATES


QUERY #1 – 16 marks
The cost to play for competitive players is $300.
1. Write a select statement that will list
the first and last names of competitive players
and how much they still owe toward their fees (calculate it).
(3 marks)

2. Use the alias ‘Outstanding’ for the calculation column.


(2 marks)

3. Only list players who are not residents AND whose fee amount is not more than
$300.
(2 marks)

4. Order the results descending by the outstanding column.


(2 marks)

RESULT SET (7 marks)


(1 mark for generating result set,
1 mark for each of three rows,
1 mark for each of three headings)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

QUERY #2 (16 marks)


The city a coach lives in is recorded using a table related to coaches.
We have been asked for a list of coaches living in two specific cities.
1. Write a select statement that will list
all coach’s first names, last names and the name of the city they live in.
(3 marks for select,
1 mark for from)

2. Use a special operator in the WHERE clause to only list coaches from Whitby or
Oshawa. (3 marks for JOIN, 2 marks for where)

RESULT SET (7 marks)


(1 mark for generating result set,
1 mark for each of three rows,
1 mark for each of three headings)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

QUERY #3 (16 marks)


The hockey organizer would like to have the following details listed in this order. The
average amount paid so far, the sum of all payments, and the sum of all outstanding
fees.
1. Write a select statement using some aggregate functions
to display the requested information.
One of the columns requires using a function in a calculation.
(3 marks for use of functions with correct fields,
3 marks for calculation inside function)

2. Ensure all calculated columns have an appropriate and meaningful alias.


(3 marks for headings)

RESULT SET (7 marks)


(1 mark for generating result set,
1 mark for each correct calculation,
1 mark for each meaningful heading)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

Week 9 Questions ------------------------------------------ SUBQUERIES, FUNCTIONS


QUERY #4 (16 marks)
The organizer wants to know which of the products that are listed in the products table
haven’t been ordered by anyone yet.
1. Write a query that will display
the product name and MSRP of products that haven’t been ordered yet.
(2 marks for select,
1 mark for from,
2 marks for where)

2. Use an IN subquery to compare the list of products


to the list of ordered products to get your result.
(3 marks for IN subquery)

RESULT SET (8 marks)


(3 marks for generating result set,
5 marks for correct row with correct columns and headings)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

QUERY #5 (16 marks)


The organizer is requesting a list of all products with a price less than or equal to the
average product MSRP.
1. Write a query that makes use of a WHERE subquery to list the product name
and MSRP of every product that with an MSRP lower than the average MSRP.
(2 marks for select,
1 mark for from,
2 marks for where)

2. Use an aggregate function in your subquery to calculate the average MSRP.


(3 marks for subquery with aggregate function)

RESULT SET (8 marks)


(1 mark for generating result set,
1 mark for each of five rows,
1 mark for each of two headings)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

Week 10 Questions ------------------------------------------ RELATIONAL SET OPERATORS


QUERY #6 (16 marks)
We’ve been asked to list any players
who are playing in both recreation and competitive leagues.
1. Write a query that uses either INTERSECT or EXCEPT to find the players
who play for both competitive and recreational leagues.
Only one of the two operators is correct.
(1 mark for each of two selects,
1 mark for each of two from,
1 marks for INTERSECT or EXCEPT)

2. List their first name, last name and date of birth.


(3 marks for correct fields)

RESULT SET (8 marks)


(1 mark for generating result set,
1 mark for correct row with correct columns and headings)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

QUERY #7 (16 marks)


1. Use UNION in a query
and a calculation to display PlayerID, PlayerName, Fees Paid, and Fees Outstanding
(with a nice heading) from both REC and COMP players who have fees outstanding.
Sort the output in descending order by amount owing (highest amount owning first)
(2 marks for each of two selects,
1/2 mark for each from,
1/2 mark for each where,
1 mark for Union,
1 mark for Order by)

RESULT SET (8 marks)


(1 mark for generating result set,
1/2 mark for each correct row,
1/2 mark for each correct columns with correct heading)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

THE MARKING SCHEME ------------------------------------------


This is what you need to use to self-assess,
and it will be what your professor uses to grade your submission.

Complete the self-assessment column in the table below,


then save the document and be sure to submit it along with your work.

 OVERALL FORMATTING – 7 marks (1 mark per query)

o Each statement is formatted so that clauses start new lines and do not contain
extraneous ‘software-generated style’ explicit declarations.

Ex.
SELECT studentFirstName, studentLastName
FROM tblAwesomeStudents
WHERE isThisStudentAwesomeOrWhat = True;

 OVERALL COMMENTING – 7 marks (1 mark per query)

o All statements include written comments using the developer’s own words that
briefly describe what the query actually does.

Ex.
/* This statement retrieves the first and last names of all students from the Awesome
Students table where the record indicates that they are indeed awesome. */

 EFFICIENT FILE EXECUTION – 14 marks

o Entire file must execute correctly


with appropriate comments, use statements, select statements, go statements
(7 marks)

o Each query must execute correctly


(1 mark per query)

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

MARKING SCHEME
Out Of Self-Assessment Actual
OVERALL FORMATTING 7
OVERALL COMMENTING 7
EFFICIENT FILE EXECUTION 14

QUERY #1
CORRECT RESULT (incl. calculation) 7
SELECT 3
FROM 2
WHERE CRITERIA 2
ORDER BY 2

QUERY TOTAL 16
QUERY #2
CORRECT RESULT 7
SELECT 3
FROM 1
JOIN CLAUSE 3
WHERE CLAUSE (SPECIAL OPERATOR) 2

QUERY TOTAL 16
QUERY #3
CORRECT RESULT 7
SELECT 3
FROM 3
USE OF FUNCTION/ AGGREGATE
3
PROCESS

QUERY TOTAL 16

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

QUERY #4
CORRECT RESULT 8
SELECT 2
FROM 1
JOIN 2
SUBQUERY WITH AGGREGATE 3

QUERY TOTAL 16
QUERY #5
CORRECT RESULT 8
SELECT 2
FROM 1
WHERE 2
SUBQUERY WITH AGGREGATE 3

QUERY TOTAL 16
QUERY #6
CORRECT RESULT 8
SELECT CLAUSES 2
FROM CLAUSES 2
INTERSECT or EXCEPT 1
CORRECT FIELDS 3

QUERY TOTAL 16
QUERY #7
CORRECT RESULT 8
SELECT CLAUSES (incl. calculation) 4
FROM CLAUSES 1
WHERE CRITERIA 1
UNION 1
ORDER BY 1

QUERY TOTAL 16
ASSIGNMENT TOTALS 140

This content is protected and may not be shared, uploaded, or distributed.


This content is protected and may not be shared, uploaded, or distributed.

Notes from the Instructor:

 All scripts are included in a single .SQL file, which upon execution will complete all
queries in the order they are listed in this assignment.

 Use ‘GO’ as the last line of each query. This way, if one of your statements is causing an
error the rest of the working statements will still execute and provide their results.

This content is protected and may not be shared, uploaded, or distributed.

You might also like