CIS 207 Oracle - Database Programming and SQL Homework: # 13 Key
CIS 207 Oracle - Database Programming and SQL Homework: # 13 Key
Run the following queries in Oracle Application Express. Paste a copy of each query
Into this word document below the questions or notepad .txt file, save and in TalonNet:
Global Fast Foods has been very successful this past year and has opened several new stores. They
need to add a table to their database to store information about each of their store’s locations. The
owners want to make sure that all entries
Have an identification number, date opened, address, and city and that no other entry in the table can
have the same email address. Based on this information, answer the following questions about the
global_locations table. Use the table for your answers.
6. Write the CREATE TABLE statement for the Global Fast Foods locations table to define the
constraints at the column level. Use the information above for the table definition. Execute the
CREATE TABLE statement in Oracle Application Express.
9. Rewrite the CREATE TABLE statement for the Global Fast Foods locations table to define the
UNIQUE constraints at the table level. Do not execute this statement.
Homework_13_Sp16.doc
section 14 & 15
Complete the following “Try It / Solve It” Exercises:
Section 14 Lesson 2, Ex 2, 3, 4, 5
2. Using the column information for the animals table below, name constraints where applicable
at the table level, otherwise name them at the column level. Define the primary key (animal_id).
The license_tag_number must be unique. The admit_date and vaccination_date columns cannot
contain null values.
Animal_id NUMBER(6)
name VARCHAR2(25)
license_tag_number NUMBER(10)
admit_date DATE
adoption_id NUMBER(5),
vaccination_date DATE
3. Create the animals table. Write the syntax you will use to create the table.
4. Enter one row into the table. Execute a SELECT * statement to verify your input. Refer to
the graphic below for input.
5. Write the syntax to create a foreign key (adoption_id) in the animals table that has a
corresponding primary-key reference in the adoptions table. Show both the column-level and
table-level syntax. Note that because you have not actually created an adoptions table, no
adoption_id primary key exists, so the foreign key cannot be added to the animals table.
Homework_13_Sp16.doc
section 14 & 15
SECTION 14 LESSON 3 – Managing Constraints
Ex. 2, 3, 5, 10, 11
Using Oracle Application Developer, click the SQL Workshop tab in the menu bar. Click the
Tables icon under the Data Browser heading. Verify that you have a table named copy_d_clients
and a table named copy_d_events. If you don’t have these tables in your schema, create them
before completing the exercises below. Here is how the original tables are related. The d_clients
table has a primary key client_number. This has a primary-key constraint and it is referenced in
the foreign-key constraint on the d_events table.
NOTE: The practice exercises use the d_clients and d_events tables in the DJ on Demand
database. Students will work with copies of these two tables named copy_d_clients and
copy_d_events. Make sure they have new copies of the tables (without changes made from
previous exercises). Remember, tables copied using a subquery do not have the integrity
constraints as established in the original tables. When using the SELECT statement to view the
constraint name, the tablenames must be all capital letters.
2.Since the tables are copies of the original tables, the integrity rules are not passed onto the new
tables; only the column datatype definitions remain. You will need to add a PRIMARY KEY
constraint to the copy_d_clients table. Name the primary key copy_d_clients_pk . What is the syntax
you used to create the PRIMARY KEY constraint to the copy_d_clients.table?
3. Create a FOREIGN KEY constraint in the copy_d_events table. Name the foreign key
copy_d_events_fk. This key references the copy_d_clients table client_number column. What is
the syntax you used to create the FOREIGN KEY constraint in the copy_d_events table?
5. Drop the PRIMARY KEY constraint on the copy_d_clients table. Explain your results.
10. If you wanted to enable the foreign-key column and reestablish the referential integrity
between these two tables, what must be done?
11. Why might you want to disable and then re-enable a constraint?
Homework_13_Sp16.doc
section 14 & 15
SECTION 15 LESSON 1 – Creating Views
Ex. 2, 3, 4
2. Create a simple view called view_d_songs that contains the ID, title and artist from the DJ on
Demand table for each “New Age” type code. In the subquery, use the alias “Song Title” for the title
column.
4. REPLACE view_d_songs. Add type_code to the column list. Use aliases for all columns.
Homework_13_Sp16.doc
section 14 & 15
SECTION 15 LESSON 2 – DML Operations and Views
Ex. 1, 2, 3
Use the DESCRIBE statement to verify that you have tables named copy_d_songs, copy_d_events,
copy_d_cds, and copy_d_clients in your schema. If you don’t, use a query to create a copy of each.
1. Query the data dictionary USER_UPDATABLE_COLUMNS to make sure the columns in the
base tables will allow UPDATE, INSERT, or DELETE. Use a SELECT statement or the Browse
Data Dictionary feature in HTML DB. All table names in the data dictionary are stored in uppercase.
2. Use the CREATE or REPLACE option to create a view of all the columns in the copy_d_songs
table called view_copy_d_songs.
3. Use view_copy_d_songs to INSERT the following data into the underlying copy_d_songs table.
Execute a SELECT * from copy_d_songs to verify your DML command. See the graphic.
1. Create a view from the copy_d_songs table called view_copy_d_songs that includes only the title
and artist. Execute a SELECT * statement to verify that the view exists.
2. Issue a DROP view_copy_d_songs. Execute a SELECT * statement to verify that the view has
been deleted.
3. Create a query that selects the last name and salary from the Oracle database. Rank the salaries
from highest to lowest for the top three employees.
5. Create a query that will return the staff members of Global Fast Foods ranked by salary from
lowest to highest.
Homework_13_Sp16.doc
section 14 & 15