Database Analysis and Design Assignment 01
Database Analysis and Design Assignment 01
Version 1.2
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:
• 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
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.
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..
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.
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
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
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
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:
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.
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
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
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
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