Database Tutorial

Course Tutorial Site

Site Admin

CIT225: Lab 4 Instructions

without comments

Lab #3: Oracle Assignment Underdevelopment

Objectives

The lab teaches you how to work with sequential and non-sequential INSERT statements across a dependent series of tables. Also, the lab teaches you how to call an API, use subqueries and literal values in the VALUES clause of the INSERT statement; and how to use a derived table instead of a table or view in a query and how to perform a correlated UPDATE statement.

The detail learning objectives are:

  • Learn how to write a set of sequential INSERT statements across a set of dependent tables.
  • Learn how to write a set of non-sequential INSERT statement by leveraging queries to discover appropriate primary key values in an independent table that you can use as foreign key values in a related dependent table.
  • Learn how to use the .NEXTVAL pseudo column in one table as a primary key value; and the .CURRVAL pseudo column in another table with a dependency on the former table as a foreign key value.
  • Learn how to call a store procedure that acts like an API (Application Programming Interface) to a set of tables.
  • Learn how to write a subquery as a derived table (or the result of a table subquery) inside the FROM clause.
  • Learn how to correlate (or join) the results of a subquery (a correlated subquery) with an external UPDATE statement.

Business Scenario

Building data-centric application software often requires that you pre-seed data in certain database tables. The process of pre-seeding involves inserting rows of data. Sometimes the Entity Relationship Diagram (ERD) can create conflicts, which require you to temporarily disable constraints to insert data.

The lab is designed to teach you how to write INSERT statements. The INSERT statements use:

  • Literal values
  • Pseudo columns for sequence values
  • Subqueries that retrieve surrogate primary key values from tables by using the natural keys of the tables

You will disable foreign key constraints and remove not null constraints to pre-seed some of the tables with data. After inserting the new data, you will add re-enable foreign key constraints and re-add not null constraints. You should use the preseed_oracle_store.sql script as a reference model for SQL syntax.

Help Section

The following is an set of sample programs and steps that address concepts in the lab. The instructor should review these in classroom or in a Google Hangout with students. Click the Instructional Material link to see the preparation lesson material.

The lab has ten parts. Each of the parts links to a SQL script file, and you should treat each file as a distinct use case that requires unit testing. The last part actually calls the nine SQL scripts in sequence and becomes an integration test of your code.

Lab Description

[25 points] Click the Lab Instructions link to open the instructions inside the current webpage.

The lab requires that you run two preparation scripts, which in their respective sequence of operation call other scripts. You will call the seeding.sql script from the /home/student/Data/cit225/oraclelib2/seed directory.

Its recommended that you create your apply_oracle_lab4.sql script in the lab4 directory first. While you’ll add to this file later, the initial file should have the following functional lines:

-- Run the prior lab script.
@/home/student/Data/cit225/oracle/lab3/apply_oracle_lab3.sql
@/home/student/Data/cit225/oracle/lib2/seed/seeding.sql
 
-- insert calls to other SQL script files here, in the order that they appear in the seeding.sql script ...
 
SPOOL apply_oracle_lab4.txt
 
-- insert your SQL statements here ... 
-- start with the validation scripts you find in the seeding.sql script.
-- copying the seeding.sql file and editing it to conform to this layout is the simplest approach to the lab. 
 
SPOOL OFF
 
-- ------------------------------------------------------------------
--  This is necessary to avoid a resource busy error. You can
--  inadvertently create a resource busy error when testing in two
--  concurrent SQL*Plus sessions unless you provide an explicit
--  COMMIT; statement. 
-- ------------------------------------------------------------------
COMMIT;

Click the Lab Instructions link to display the lab steps:

Written by michaelmclaughlin

February 1st, 2018 at 3:51 pm

Posted in