You are on page 1of 6

CP5503 Enterprise Database Systems Oracle

Assignment Part 1
Due date: A draft (hard copy) on Tuesday-Week4 in class
Final soft-copy on Friday-Week5 5 pm via LearnJCU

Assignment Part 1 Objectives & Structures:


This part provides experience with creating database tables using SQLDeveloper. You are going to create a
simple Library database for the Springfield College. There are three tasks of the assignment:
Task1 (5pts): You need to use SQLDeveloper or Oracle Enterprise Manager to create a database schema
called LIBDB to store all the database objects for this assignment. You also need to grant the appropriate
privileges to the LIBDB users for creating the database objects. You need to follow the principle of least
privilege when granting privileges. Make sure that the submitted script includes all the required GRANT
statements.
Task1 submission file:
Produce a script called A1Task1.sql which contains SQL statement(s) for
- creating the LIBDB user
- granting appropriate privileges to the LIBDB user
Task 2 (20pts): You need to create tables and constraints specified below. You should use SQLDeveloper to
write SQL statements to create the tables and constraints.
You must use the table and column names as shown in Table 1 to 11.
Choose the appropriate Oracle data type for each column.
Task 2 Table Descriptions
Table 1: Author
Column
author_id
author_fname

Data Type
Positive whole number
Variable length string

author_lname

Variable length string

Table 2: Book_Author
Column
Data Type
book_author_id
Positive whole number
author_id
Positive whole number

Comments
Primary key
Max of 50 characters; null not allowed; (author_fname, author_lname)
is unique
Max of 50 characters; null not allowed

book_id

Positive whole number

Comments
Primary key
Foreign key to the table Author; (author_id, book_id) is unique; null not
allowed
Foreign key to the table Book; null not allowed

Table 3: Publisher
Column
publisher_id
publisher_name
publisher_url
publisher_email

Data Type
Positive whole number
Variable length string
Variable length string
Variable length string

Comments
Primary key
Max of 50 characters; null not allowed
Max of 100 characters; null allowed; unique
Max of 50 characters; null allowed; unique

Table4: Cat (Category)


Column
Data Type
cat_id
Positive whole number
cat_name
Variable length string

Comments
Primary key
2 characters; null not allowed; book category must belong to one of the
following items:
BU (business)
LA (law)
AC (accounting)
IT (info tech)
TO (tourism)
HO (hospitality)
HU (human resource)
UN (unclassified or general)

Table 5: Book
Column
book_id
isbn
publisher_id
title
cat_id

Data Type
Positive whole number
Variable length string
Positive whole number
Variable length string
Positive whole number

shelf_letter
call_number
no_of_pages
no_of_copies
date_arrived

Variable length string


Positive whole number
Positive whole number
Positive whole number
Date/Time

Table 6: Copies
Column
copy_id
book_id
copy_number

Data Type
Positive whole number
Positive whole number
Positive whole number

Comments
Primary key
Foreign key to the table Book; null not allowed
null not allowed; (book_id, copy_number) is unique; copy_number is
between 1 and no_of_copies (Book) -- you do not need to implement
this condition, it will be done by a trigger in Assignment - Part2

Table 7: Subject
Column
subject_id
subject_name
subject_code

Data Type
Positive whole number
Variable length string
Variable length string

Comments
Primary key
Max of 50 characters; null not allowed
Max of 15 characters; null not allowed; unique

Table 8: Book_Subject
Column
Data Type
book_subject_id
Positive whole number
book_id
Positive whole number
subject_id
Positive whole number

Comments
Primary key
Max of 20 characters; null not allowed; unique
Foreign key to the table Publisher; null not allowed
Max of 100 characters; null not allowed
Foreign key to the table Cat; null not allowed; (shelf_letter,
call_number) is unique
1 character from A to Z; null not allowed
From 1 to 999
null allowed
must be >= 1; null not allowed
Default should be the current date and time (use a function to generate
the default value); null not allowed

Comments
Primary key
Foreign key to the table Book; null allowed
Foreign key to the table Subject; null not allowed; (book_id, subject_id)
is unique
2

subject_ref

Variable length string

1 character: P (prescribed) or R (reference) or null

Table 9: Loan
Column
loan_id
borrower_id
copy_id
date_out

Data Type
Positive whole number
Positive whole number
Positive whole number
Date/Time

date_due

Date/Time

date_returned

Date/Time

Comments
Primary key
Foreign key to the table Borrower; null not allowed
Foreign key to the table Copies; null not allowed
Default should be the current date and time (use a function to generate
the default value);
null not allowed;
When data is filled it should be <= current date -- you do not need to
implement this condition, it will be done by a trigger in Assignment Part2 (noted that sysdate function cannot be used in check constraint)
Default should be one week from the current date and time (use a
function to generate the default value); null not allowed
When data is filled it should be checked if date_due is 7 days more than
date_out
null allowed;
When data is filled it should be >= date_out;
When data is filled it should be <= current date -- you do not need to
implement this condition, it will be done by a trigger in Assignment Part2

Table 10: Borrower


Column
borrower_id
borrower_fname

Data Type
Positive whole number
Variable length string

borrower_lname
borrower_email

Variable length string


Variable length string

borrower_phone
borrower_street
borrower_suburb
borrower_postcode
borrower_type
date_registered

Variable length string


Variable length string
Variable length string
Variable length string
Variable length string
Date/Time

Table 11: Log_Table


Column
Data Type
exc_id
Positive whole number
exc_trigger
Variable length string
exc_table

Variable length string

exc_key_value
exc_date

Positive whole number


Date/Time

Comments
Primary key
Max of 50 characters; null not allowed; (borrower_fname,
borrower_lname) is unique
Max of 50 characters; null not allowed
Max of 50 characters; null not allowed; unique; contains an @ (Bonus:
if being able to set x@x.x)
Max of 20 characters; null allowed
Max of 50 characters; null not allowed
Max of 50 characters; null not allowed
four numerical digits; from 0200 to 9999; null not allowed
1 character: S(student) or L(lecturer) or O(other) ; null not allowed;
Default should be the current date and time (use a function to
generate the default value); null not allowed

Comments
Primary key
Trigger name in which the exception occurred
Max of 30 characters null not allowed
Name of the table containing the exception
Max of 30 characters null not allowed
Primary key value of the row with the exception
The date and time when the exception occurred; Default should be the

current date and time (use a function to generate the default value);
null not allowed.
exc_text

Variable length string

Message explaining the error

Task 2 Referential Integrity Constraints


Define referential integrity constraints as defined in Tables 1 through 10. You should enforce each
referential integrity constraint.
You should choose appropriate actions when referenced rows are deleted. When a book is deleted, the
associated rows in the Copies table are deleted and the associated foreign key values in the Book_Subject
table should be set null. In addition, when a subject is deleted, the associated rows in the Book_Subject table
should be deleted. For other referential integrity constraints involving required foreign keys (nulls not
allowed), deleting a referenced row in a parent table should not be permitted if there are associated
referencing rows in a child table.
Task 2 Check Constraints and Unique Constraints
Here is the summary of check constraints or unique constraints that you have to create when creating related
tables.
- Positive whole number is set for primary keys
- The combination of author_fname and author_lname is unique in the Author table
- The combination of author_id and book_id is unique in the Book_Author table
- cat_name must belong to one of the following items: BU, LA, AC, IT, TO, HO, HU, UN
- The combination of shelf_letter and call_number is unique in the Book table
- shelf_letter is 1 character from A to Z
- call_number is a number from 1 to 999
- no_of_copies >= 1
- The combination of book_id and copy_number is unique in the Copies table
- The combination of book_id and subject_id is unique in the Book_Subject table
- subject_ref is null or P or R
- subject_code is unique in the Subject table
- date_due = date_out + 7
- date_returned >= date_out
- The combination of borrower_fname and borrower_fname is unique in the Borrower table
- borrower_postcode is a string of four numerical digits from 0200 to 9999
- borrower_type is S or L or O
- borrower_email contains an @ (Bonus: if being able to set x@x.x)

Task2 submission file:


Produce a script called A1Task2.sql which contains valid SQL statement(s) for
- creating the required database tables and constraints
Please note that any non-executable statement must be declared as a comment i.e. putting double hyphens in
front of the non-executable statement, for example:
-- Table Author
CREATE TABLE Author
(
...
);

Task 3: Loading Data, Creating Sequences and Users (10pts)


You should use the file (Ass1_data.zip) provided to construct INSERT statements to load the data into the
tables. You need to create sequence generators for tables to facilitate the auto generation of primary key
values. You will then write INSERT statements to load the data. The sequence generators must be used in the
INSERT statements. You also need to create a database user account for each user found in the Borrower
table. These users can insert new loan records However, they cannot delete any data.
Task3 submission file:
Produce a script called A1Task3.sql which contains SQL statement(s) for
- creating the required sequence generators
- inserting data into the tables
- creating the database user accounts and granting appropriate privileges
Task 4 (10 points):
(a) Produce an ER (entity-relationship) diagram for the LIBDB database. You must use the tool MySQL
Workbench to do this task. MySQL Workbench is free to download at http://mysqlworkbench.org/.
Here is the picture of the three tables Cat, Publisher and Book created by MySQL Workbench.

Hint: Add a new model: File New Model; double-click on Add Diagram; click
or press T and then click
on the Diagram editor to add a new table; double-click on the new-added table to edit: you can now change
the table name, define columns and foreign keys; when completed you can export the diagram: File Export
Export as PNG.

b) Good database design is to achieve the third normal form (3NF) of the database. Is LIBDB at the 3NF? If not,
how can you re-design it to achieve 3NF?
Note: You can find information about normalization at http://support.microsoft.com/kb/283878 or any other
relevant resources.
Task4 submission file:
Produce a word file as A1Task4.docx including your answers on a and b.

SUBMISSION ON LEARNJCU
Submission date: By 5 pm Friday Week 5 22/08/2014.
Submit your final copy as a zip file named jcnumber.zip (e.g. jc123456.zip) containing A1Task1.sql,
A1Task2.sql, A1Task3 and A1Task4.docx on LearnJCU. You can find the submission link inside the Assignments
folder which is located inside the Subject Materials folder.

You might also like