Database Tutorial

Course Tutorial Site

Site Admin

Instructions

without comments

Lab #4: Insert Patterns

Learn how to write INSERT statements that include literal values, sequence values, and scalar subqueries. The following bullets describe the values:

  • The literal values can be numbers, dates, or strings. Numbers are inserted without delimiters. Strings and dates are inserted with single quote delimiters. Dates are single quote delimited and must conform to one of the default format masks or use the TO_DATE function to use a non-default format mask.
  • The sequence values use the .nextval for new primary key sequence values and .currval for foreign key sequence values where the inserted values are sequential.
  • The scalar subqueries use the natural key in the WHERE clause to discover a row, and the subquery’s SELECT-list returns the primary key value of that row. Scalar subqueries are the way developers discover and copy a primary key into a foreign key column.

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

[110 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/oracle/lib1/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/lib1/seed/seeding.sql
 
-- ------------------------------------------------------------------
-- Call the lab versions of the file.
-- ------------------------------------------------------------------
@@group_account1_lab.sql
@@group_account2_lab.sql
@@group_account3_lab.sql
@@item_inserts_lab.sql
@@create_insert_contacts_lab.sql
@@individual_accounts_lab.sql
@@update_members_lab.sql
@@rental_inserts_lab.sql
@@create_view_lab.sql
 
-- Open log file.  
SPOOL apply_oracle_lab4.txt
 
-- ------------------------------------------------------------------
--  The following queries should be placed here:
-- ------------------------------------------------------------------
--  6(c) diagnostics for the individual_accounts.sql script.
--  7(c) diagnostics for the update_members.sql script.
--  8(c) diagnostics for the rental_inserts.sql script.
--  9(c) diagnostics for the create_view_lab.sql script.
-- ------------------------------------------------------------------
 
-- Close log file.
SPOOL OFF
 
-- Make all changes permanent.
COMMIT;

Click the Lab Instructions link to display the lab steps:

Test Case

Click the Test Case Instructions link to open the test case instructions inside the current webpage.

Written by michaelmclaughlin

August 13th, 2018 at 10:50 am

Posted in