Sei sulla pagina 1di 4

CIS 211C Oracle - Database Programming and SQL HOMEWORK: # 13

DUE:

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 return via TalonNet: Before doing any of the assigned questions below, remember that you are not to execute the commands on the database table that are currently available in the APEX environment. First you are to make copies of the tables and give the table the same names but with copy_ proceeding the original names. For example for the d_cds table the copied table would be called copy_d_cds. For example you would use the following command to create the copy_d_cds table: CREATE TABLE copy_d_cds AS SELECT * FROM d_cds; If you need to start with a fresh copy of the copy tables, you can remove the table using the following command format: DROP TABLE copy_d_cds; You might want to reference the student resource link on the class website and use the creating a table handout. Complete the following Try It / Solve It Exercises:

Section 8, Lesson 1 Exercise 1, 2, 3 1. Complete the GRADUATE CANDIDATE table instance chart. Credits is a foreign-key column referencing the requirements table.

2. Write the syntax to create the grad_candidates table. Column Name student_id last_name first_name Credits graduation_date Key Type Nulls/Unique FK column Datatype NUMBER VARCHAR2 VARCHAR2 NUMBER DATE Length 6 15 15 3

3. Confirm creation of the table using DESCRIBE.

Homework_13_Fa11.doc DP Section 8

Section 8 Lesson 2, Exercise 1

1. Using the examples provided in Tell Me/Show Me, create each of the three time-zone tables. 1 2 3 TIMESTAMP WITH LOCAL TIME ZONE INTERVAL YEAR TO MONTH INTERVAL DAY TO SECOND

LONDON

NEW YORK

TOKYO

SHANGHAI

Section 8, Lesson 3 Exercise 3, 4, 5, 6, 8

Before beginning the practice exercises, execute a DESCRIBE for each of the following tables: o_employees and o_jobs. These tables will be used in the exercises. You will need to know which columns do not allow null values. NOTE: If students have not already created the o_employees, o_departments, and o_jobs tables they should create them using the four steps outlined in the practice. a. Create the three o_tables jobs, employees, and departments using the syntax: CREATE TABLE o_jobs AS (SELECT * FROM jobs); CREATE TABLE o_employees AS (SELECT * FROM employees); CREATE TABLE o_departments AS (SELECT * FROM departments);
Homework_13_Fa11.doc DP Section 8

b. Add the Human Resources job to the jobs table: INSERT INTO o_jobs (job_id, job_title, min_salary, max_salary) VALUES('HR_MAN', 'Human Resources Manager', 4500, 5500); c. Add the three new employees to the employees table: INSERT INTO o_employees (employee_id, first_name, last_name, email, hire_date, job_id) VALUES(210, 'Ramon', 'Sanchez', 'RSANCHEZ', SYSDATE, 'HR_MAN'); d. Add Human Resources to the departments table: INSERT INTO o_departments(department_id, department_name) VALUES (210,'Human Resources'); 3. In your o_employees table, enter a new column called Termination. The datatype for the new column should be VARCHAR2. Set the DEFAULT for this column as SYSDATE to appear as character data in the format: February 20th, 2003. Add the following data: employee_id = 210 first_name = Ramon last_name = Sanchez email = RSANCHEZ hire_date = todays date job_id = HR_MAN

4.Create a new column in the o_employees table called start_date. Use the TIMESTAMP WITH LOCAL TIME ZONE as the datatype.

Homework_13_Fa11.doc DP Section 8

5. Truncate the o_job_description table. Then do a SELECT * statement. Are the columns still there? Is the data still there? 6. What is the distinction between TRUNCATE, DELETE and DROP for tables? 8. Add the following comment to the o_jobs table: "New job description added" View the data dictionary to view your comments. 10. F_staffs table exercises: 0 a. Create a copy of the f_staffs table called copy_f_staffs and use this copy table for the remaining labs in this lesson. 1 b. Describe the new table to make sure it exists.

1 c. Drop the table. d. Try to select from the table. 1 e. Investigate your recyclebin to see where the table went. g. Undrop the table.

Homework_13_Fa11.doc DP Section 8