Swinburne University of Technology
Department of Foundation and Pathways
INF10004 Database, Analysis and Design Assignment 1
Version 1.2
Assignment Value: 10% of your final mark
The assignment is to be done in pairs
Due Date/Time: End of week 7 11:59PM Sunday 07 April 2019
Submission Requirements
Create a text file that contains all of the statements required for all tasks of this assignment.
Your scripts must work with Oracle iSQL Junior
You must submit your assignment via Canvas submission link by the due date.
(Note: Late submissions will attract a penalty)
In the week 8 Lab you must demonstrate the assignment to your tutor using your script using
ISQL Junior. Make sure that you have a soft copy of the script with you in the lab.
Background:
A database analyst has developed the following ER Diagram.
Task 1:
1A. Create Text File
Create a text file named ASS1.TXT
Add your Student ID(s) and Student name(s) the first line of this file.
1B. Create Tables and Constraints
Write Create Table SQL statements based on the above ERD.
• All tables must have primary keys.
• All tables must have appropriate foreign key constraints.
• Foreign keys must have the same name, datatype and size of the primary key that they refer to •
The following columns datatypes and sizes must be used
bid, authid number(4)
title, sname, fname varchar2(30)
sellingprice, payrate number(6,2)
• The following constraints must be applied to the appropriate tables. All unique and check
constraints must be named.
Page 1 of 12
Table Column Type Range
author sname & fname Unique
book title Not Null
book sellingprice Check not negative
allocation payrate Check 1 to 79.99
Append the SQL statements to the ASS1.TXT file.
Prefix each CREATE TABLE statement with a prompt statement.
e.g.
Prompt Creating Table Employee;
CREATE TABLE Employee (...
empid NUMBER (3),
empname VARCHAR2(20) Not Null,
empage NUMBER(3), Primary Key (empid),
CONSTRAINT UC_EMPAGE UNIQUE (empage),…. );
1C. Valid Insert Statements
Append SQL Insert statements to the ASS1.TXT file that will add the data to the 3 tables based on
the following information:
This sample data has been obtained from handwritten documents supplied by the client. The data
below has not been stored or obtained from a computer system.
AUTHOR DETAILS BOOK DETAILS
Author Id Surname First Name Selling
40 Ziggle Carl Book Id Book Title Price
42 Taylor Tayla 101 Knitting with Dog Hair 6.99
44 Merdovic Damir
105 Avoiding Large Ships 11
107 Dealing with stuff 6.5
45 Grossman Paul
108 Teach fish to sing 10.99
47 Ziggle Annie
109 Guide to hands free texting 10.5
48 Zhao Cheng
113 You call that a lecture? 17.5
50 Phan Annie
ALLOCATION DETAILS
Item Id Author Payrate
101 42 $25
101 45 $32
108 47 $35
113 48 $40
109 47 $42
105 42 $26
105 47 $25
105 40 $19
107 42 $35
108 40 $45
Page 2 of 12
1D. Invalid Insert Statements
Write 4 Insert that will fail because of data constraints.
Statement 1 must fail due when adding a duplicate combination of author sname & fname.
Statement 2 must fail due when adding a textboox with a null title.
Statement 3 must fail due when adding a book with a negative selling price. Statement
4 must fail due when adding an allocation out of range payrate..
Append SQL Insert statements to the ASS1.TXT file.
Prefix each statement with an appropriate prompt statement.
Page 3 of 12
1E. SQL Queries
Write the following queries and add each to the ASS2.TXT file.
Prefix each statement with an appropriate prompt statement.
Query Requirement Sample Output (data is incorrect)
1 Write a query that lists rows from
the allocation table. Columns:
• book id
• author id
• payment rate
Sequence:
• book id
• author id
2 Write a query that lists rows from the
allocation and book tables.
Columns:
• book id
• book title
• author id
• payment rate
Sequence:
• book id
• author id
3 Write a query that lists rows from the
allocation, book and author tables.
Columns:
• book id
• book title
• book price
• author id
• author name
• payment rate
Sequence:
• book id
• author id
4 Write a query that lists the average
price of rows in the book table.
The heading must match the example
shown.
Page 4 of 12
5 Write a query that lists rows from
the book table Columns:
• book id
• book title
• book price Restriction:
• Only list rows that
have a price less than the average
price Sequence:
• book id
6 Write a query that counts the total
number of rows in the allocation
table grouped by book id
Columns:
• book id
• count Sequence:
• count
• book id
7 Write a query that counts the total
number of rows in the allocation
table grouped by book id
Columns:
• book id
• book title
• count Sequence:
• count
• book id
8 Write a query that counts the total
number of rows in the allocation
table grouped by book id.
Only show totals greater than 1
Columns:
• book id
• book title
• count Sequence:
• count
• book id
Page 5 of 12
9 Write a query that lists rows from the
allocation and author tables.
Columns:
• author id
• author name
• book id Sequence:
• author id
• book id
10 Write a query that lists rows from the
allocation and author tables.
Columns:
• author id
• author name
• book id Sequence:
• author id
• book id
Ensure that all authors are listed
even if do not included in the
allocation table
11 Write a query that lists rows from the
allocation, book and author tables.
Columns:
• author id
• author name
• book id
• book title Sequence:
• author id
• book id
Ensure that all authors are listed -
even if they are not included in the
allocation table
Page 6 of 12
Task 2:
The ERD has been modified. A new entity named WorkSession has been added.
This entity is used to record the number of hours worked in a week by an author on the development of
a
book
2A. Create Tables and Constraints
Write Create Table SQL statements Work Session table that you have created
• The table must have a primary key.
• The table must have appropriate foreign key constraints.
• Foreign keys must have the same name, datatype and size of the primary key that they refer to
• The following columns datatypes and sizes and named constraints must be used
Column DataType Constraint
WorkYear number(4) Range 2017 - 2019
WorkWeek number(2) Range 1-52
WorkHours number(4,2) Range 0.5 – 99.99
Append the SQL statements to the ASS1.TXT file.
Prefix the CREATE TABLE statement with a prompt statement.
Page 7 of 12
2C. Valid Insert Statements
Append SQL Insert statements to the ASS1.TXT file that will add the data to
the worksession table based on the following information:
Item Id Author Id Year Week Hours
101 42 2018 5 5
101 42 2018 6 4
101 42 2018 7 5
101 45 2018 5 10
101 45 2018 7 10
105 42 2018 5 6
105 47 2018 4 8
105 47 2018 6 7
105 47 2018 8 8
108 40 2017 52 4
108 40 2018 4 15
108 40 2018 6 6
108 47 2018 8 4
109 47 2018 5 5
109 47 2018 6 5
113 48 2018 10 15
113 48 2018 11 4
113 48 2018 12 1
2D. Invalid Insert Statements
Write five Insert SQL statements that must fail because of foreign key constraints and data constraints.
Append SQL Insert statements to the ASS1.TXT file. Prefix
each statement with a prompt statement.
Item Id Author Id Year Week Hours Reason for failure
101 48 2018 1 1 bid/authid combination does NOT exist in parent
109 42 2018 2 2 bid/authid combination does NOT exist in parent
101 42 2020 9 6 out of range workyear
101 45 2018 55 3 out of range workweek
108 40 2018 7 120 out of range workhours
Page 8 of 12
2E. SQL Queries
Write the following queries and add each to the ASS1.TXT file. Prefix
each statement with an appropriate prompt statement.
Query Requirement Sample Output (data is incorrect)
1 Write a query that lists rows from the
work table.
Columns:
• author id
• work year
• work week
• work hours Sequence:
• author id
• work year
• work week
2 Write a query that sums the total
number of hours worked by each
author by each year.
Columns:
• author id
• work year
• total hours Sequence:
• total hours descending
• author id
Page 9 of 12
3 Write a query that lists rows from
the work table. Columns:
• book id
• author id
• work year
• work week
• work hours Sequence:
• book id
• author id
• work year
• work week
4 Write a query that sums the total
number of hours worked by each
book by each author by each year.
Columns:
• book id
• author id
• work year
• total hours Sequence:
• book id
• author id
• work year
5 Copy and Modify above query
The 4th column must show the total
hours worked multiplied by the pay
rate for the author/book.
Page 10 of 12
Task 3:
Write a series of SQL statements that DROP all tables that were created in Tasks above.
(NOTE: You must determine the correct sequence in which to drop these tables).
Each statement must end with a semi-colon.
E.g.: DROP TABLE BRANCH ;
DROP TABLE EMPLOYEE ;
SQL script Instructions
Your SQL statement must follow these rules:
a. Each SQL statement must end with a semi colon ;
b. Each SQL statement must be preceded by a PROMPT statement
(Except Insert statements where only 1 statement is required for where multiple rows
are inserted in to the same table)
c. Each SQL Keyword in a Query (SELECT, FROM, WHERE etc) must be at the beginning of a
new line
--Example 1 Filename: SAMPLE_1.TXT:
Prompt Create the employee table;
CREATE TABLE employee ( empid NUMBER,
empname VARCHAR2(30) PRIMARY KEY );
Prompt Insert data into employee table;
INSERT INTO employee (empid, empname) VALUES (1, 'Olga');
INSERT INTO employee (empid, empname) VALUES (2, 'Boris');
Prompt Query 1a;
SELECT empid, empname
FROM employee
WHERE empid >= 1
AND empid <=5
ORDER BY 2;
Page 11 of 12
Marking Guide:
Start with 10 marks. Then apply any penalties.
Errors
Task 1
Creation of PK constraints Lose 2 marks for each error found
Creation of FK constraints
Creation of PK and FK values
Add Valid Data Lose 1 mark for each row that is not added correctly
Add InValid Data Lose 2 marks for each row not competed or if the row is
added to a table
Queries Lose 1 mark for each query that is incorrect
Task 2
Creation of PK constraints Lose 2 marks for each error found
Creation of FK constraints
Creation of PK and FK values
Add Valid Data Lose 1 mark for each row that is not added correctly
Add InValid Data Lose 2 marks for each row not competed or if the row is
added to a table
Queries Lose 1 mark for each query that is incorrect
Page 12 of 12