Database Tutorial

Course Tutorial Site

Site Admin

Lab #6: Oracle

with 22 comments

Lab #6: Oracle Assignment

Objectives

The lab is designed to teach you how to alter table structures, insert related data across two or more tables, and how to update data in a table. Specifically, you should learn the following:

  • Learn how to use the ALTER statement to add two new columns and add a foreign key constraint to an existing table.
  • Learn how to use the CREATE statement to create a new table with foreign key constraints.
  • Learn how to use the ALTER statement to modify a column’s name.
  • Learn how to couple several INSERT statements together into a transaction.
  • Learn how to use the UPDATE statement to change data.

Overview

The lab is designed to teach you how to alter the structure of an existing table, how to insert into data into a series of tables, and how to update existing data in a table.

ALTER Statement

  • Add new columns to an existing table.
  • Add new column constraints to an existing table.
  • Modify columns in an existing table, like changing their data types, null or not null properties, and physical size.
  • Modify column constraints in an existing table.
  • Drop a column from an existing table.
  • Remove a constraint from a table.

CREATE Statement

  • Create a new table with columns and constraints.
  • Create a new sequence.

INSERT Statement

  • Insert a new row into a table with a VALUES clause or subquery.
  • Sequencing INSERT statements lets you manage primary and foreign key assignments with the .NEXTVAL and .CURRVAL pseudo columns.
  • Non-sequencing INSERT statements compels you to use subqueries to lookup a primary key value with a SELECT statement, and lets you use the returned value in the scope of the INSERT statement.

Transaction Control

Transaction Control Language (TCL) lets you build robust application software by extending ACID-compliant control across multiple INSERT, UPDATE, and DELETE statements.

  • A SAVEPOINT lets you mark a starting point, like a bookmark in a book.
  • A ROLLBACK lets you undo work to the beginning of a session, the last COMMIT statement, or to a SAVEPOINT.
  • A COMMIT lets you make adds, deletes, and changes permanent.

Help Section

The following is an article that qualifies SQL join concepts, logic, implementation, and inheritance tree:

The lab has four parts.

Lab Description

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

Test Case

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

Written by michaelmclaughlin

May 27th, 2014 at 1:51 pm

Posted in

22 Responses to 'Lab #6: Oracle'

Subscribe to comments with RSS or TrackBack to 'Lab #6: Oracle'.

  1. Step 1 at the end it says:
    Both columns should use a NUMBER data type in Oracle, and an int unsigned data type.
    It should have a “for mySQL” after

    Matt Brandt

    27 May 14 at 4:04 pm

  2. Matt, It should be fixed now.

    michaelmclaughlin

    28 May 14 at 12:56 am

  3. 3a.
    The check code to make sure I renamed the column correctly is correct. However, the description above it reads, “The following query checks whether you’ve entered three compliant rentals and rental items:”

    I think that should be the description for 3b and 3a checkcode description should be modified.

    Abel Goodwin

    29 May 14 at 2:04 pm

  4. “All three of the rentals should be rented by Harry, Ginny, or Lily Luna Potter respectively”

    Should be “and” Lily Potter if you are going to say respectively.

    J.K. Rowling

    29 May 14 at 3:33 pm

  5. Looks like step 1 is still missing the “for MySQL” qualifier that Matt Brandt mentioned above.

    Gabe Ventilla

    17 Jun 14 at 3:21 pm

  6. Gabe, It’s fixed.

    michaelmclaughlin

    18 Jun 14 at 7:18 pm

  7. The output validation result in step 2 should probably show last_update_date instead of last_updated_date.

    Hector Valles

    21 Oct 14 at 10:05 pm

  8. Thanks, changed above.

    michaelmclaughlin

    22 Oct 14 at 12:31 am

  9. In step #1, please clarify that the RENTAL_ITEM_PRICE does not need to have a NOT NULL constraint on it until later…

    Gabe Ventilla

    22 Oct 14 at 4:03 pm

  10. The second validation output for 4c that displays the new structure and data set of the COMMON_LOOKUP table shows the old data of VHS tapes from older files, and not BLU-RAY, not sure what output should look like as such

    Jonathan Harmon

    22 Oct 14 at 8:51 pm

  11. Jonathan, There were a couple other mistakes. I’ve believe they’re all fixed.

    michaelmclaughlin

    25 Oct 14 at 4:54 pm

  12. Gabe, please review my changes and advise if you think more is required.

    michaelmclaughlin

    25 Oct 14 at 5:07 pm

  13. This part is very confusing:
    •Add two new rows to the COMMON_LOOKUP table to support the 'HOME' and 'WORK' possibilities for the TELEPHONE_TYPE column. (Note: This means you’ll need to change the value of foreign keys in the TELEPHONE_TYPE column of the TELEPHONE table to one of those found in the new COMMON_LOOKUP table rows.)

    I’m not sure where we are supposed to point the foreign key constraint to.

    Keith Banner

    31 Oct 14 at 11:36 pm

  14. Keith, I’m not sure how you conclude that you need to redirect the foreign key constraint? The change made to the table adds (inserts) two new rows in the COMMON_LOOKUP table. The new rows hold valid primary key values that should replace the pre-existing foreign key values in the TELEPHONE table rows that point to the wrong rows in the COMMON_LOOKUP table. A frequent occurrence when design changes occur, unfortunately, I don’t want to give up the actual solution:

    UPDATE   telephone
    SET      telephone_type = (A scalar subquery WHERE the NEW ROWS are found.)
    WHERE    telephone_type = (A scalar subquery WHERE the OLD ROWS are found.);

    michaelmclaughlin

    1 Nov 14 at 1:40 am

  15. In step# 3d, I think it would be helpful to specify that all four rental items should refer to the new movies inserted into the item table in step 3b.

    Gabe Ventilla

    4 Nov 14 at 3:47 am

  16. In step# 3d, it is mentioned that “You should set the addresses for the Potter family members in the city of Provo, Utah”. The addresses are, however, set in the prior step (3c) so I think this comment would be a better fit there.

    Gabe Ventilla

    4 Nov 14 at 3:51 am

  17. Gabe, That’s a good catch. I’ve moved the paragraph from 3(d) to 3(c).

    michaelmclaughlin

    6 Nov 14 at 12:41 pm

  18. Gabe, I’ve added a sentence qualifying this inside paragraph 3(d).

    michaelmclaughlin

    6 Nov 14 at 12:48 pm

  19. For part 4 a, the line above the verification query reads that it verifies the addition of columns. However, shouldn’t it say the verification that we have dropped the indexes

    Christian

    3 Feb 15 at 2:08 pm

  20. Do you have a file name inconsistency in the apply_oracle_lab6.sql script example. You are calling the lab6 file from the lab5 folder.

    Jonathan

    20 Feb 15 at 6:04 pm

  21. Jonathan, You’re right. I’ve fixed it in the web page.

    michaelmclaughlin

    7 Mar 15 at 1:18 am

  22. Christian, You’re right the sentences for 4(a) were misleading. I’ve updated them to represent what they’re doing. If you feel more is required, post another comment.

    michaelmclaughlin

    8 Mar 15 at 4:49 pm

Leave a Reply