DBM 449 LAB 1 Oracle Joins

$ 20

GENERAL OVERVIEW
Scenario/Summary
My colleague, Ann Henry, operates a regional training center for a commercial software organization. She created a database to track client progress so she can analyze effectiveness of the certification program. CLIENT, COURSE, and COURSE_ACTIVITY are three of the tables in her database. The CLIENT table contains client name, company, client number, pre-test score, certification program and email address. The COURSE_ACTIVITY table contains client number, course code, grade, and instructor notes. The COURSE table contains the course code, course name, instructor, course date, and location. Although she and her instructors enter much of the data themselves, some of the data are extracted from the corporate database and loaded into her tables.

Loading the initial data was easy. For grade entry at the end of each course, a former employee created a data entry form for the instructors. Updating most client information and generating statistics on client progress is not easy because Ann does not know much SQL. For now, she exports the three tables into three spreadsheets. To look up a grade in the COURSE_ACTIVITY spreadsheet, she first has to look up client number in the CLIENT spreadsheet. While this is doable, it is certainly not practical. For statistics, she sorts the data in the COURSE_ACTIVITY spreadsheet using multiple methods to get the numbers she needs.

Every month, Ann’s database tables need to be refreshed to reflect changes in the corporate database. Ann describes this unpleasant task. She manually compares the contents of newly extracted data from corporate to the data in her spreadsheets, copies in the new values, and then replaces the database contents with the new values.

Ann needs our help. Let’s analyze her situation and determine what advanced SQL she could use to make her tasks easier.
     
L A B O V E R V I E W

Scenario/Summary

The purpose of this lab is to explore join operators to determine which, if any, are appropriate for solving Ann’s business problems, as described in this week’s lecture.

Since Ann prefers to work from Excel spreadsheets, she wants her CLIENT and COURSE_ACTIVITY tables exported into one spreadsheet rather than two, as she is currently using. We need to determine which, if any, of the join operators will provide the data she wants for the single spreadsheet. (Note: we will not perform the export, just determine how to retrieve the necessary data.) Using the spreadsheet, she will be able to determine:

  1. Which course(s) a specific client has taken
  2. What grade(s) a specific client has earned in a specific course
  3. Which clients did not take any courses
  4. Which courses were not taken by any client

Here are results from DESCRIBE commands that show structure (columns and their data types) of tables CLIENT and COURSE_ACTIVITY. You may refer to it while constructing your queries.

SQL*Plus: Release 10.2.0.1.0 — Production on Thu Jun 14 22:38:52 2007

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 — 64bit Production
With the Partitioning, OLAP and Data Mining Options

SQL> desc course_activity

SQL>

For this lab you will be creating several documents. First, write your queries in Notepad to create a script file that will contain all of the queries asked for in lab steps 4 through 13. You can (and should) test each query as you write it to make sure that it works and is returning the correct data. Once you have all of your queries written then create a SPOOL session and run your entire script file. Be sure that you execute a SET ECHO ON session command before running the file so that both the query and the output will be captured in the SPOOL file. IMPORTANT: If you are using Windows Vista you will need to create a directory on your C: drive to SPOOL your file into. Vista will not allow you to write a file directly to the C: drive. This will give you two files for the lab. The third file will the be the Lab1 Report document found in Doc Sharing. You will need to put your responses to the questions asked in the various lab steps.

Now let’s begin.

L A B S T E P S

STEP 1: Start Oracle SQL*Plus via Citrix

Log into the Citrix iLab environment. Open your Oracle folder, select SQL Plus and log in to your database instance. Use “sys” as User Name, and “oracle” as the Password. Enter the Host String as “DB9999.world as sysdba” where 9999 is the database number you have been assigned.

STEP 2: Initialize tables

Download the pupbld.sql and Lab1_init.sql files associated with the links to your C: drive or to the F: drive in your Citrix environment. You will need to open each of the files and edit the connection string to reflect your instance name. The pupbld.sql file has two connections strings; one at the top of the script and another at the bottom. Be sure to change both of these to reflect your instance name.

Once you have done this then run the pupbld.sql script first (DO NOT copy and paste it) in your SQL*Plus session. The script will create the product_user_profile synonym in the SYSTEM account which will be used each time you log in as a normal user.

Next run the lab1_init.sql script in your session. The script will create a new user (DBM449_USER) that will be used in various labs in this course. You can find the password for this new user by looking at the CREATE USER statement in the script file. Disregard the DROP TABLE error messages. They occur because the script is designed to work regardless of whether you have already created the tables or not. This way, you may run it if you ever decide to resent the contents of your tables to the original values. When you run the script for the first time, the error messages appear as you attempt to drop tables that do not exist.

Once the script has finished you will be logged into the new user and ready to start your lab.

STEP 3: Verify your tables

You want to verify that everything completed successfully. To do this execute a SELECT * FROM TAB statement to make sure all 5 tables were created and then you can execute a SELECT COUNT(*) FROM statement using each of the table names. You should find the following numbers of records for each table.

  • CLIENT table – 5 rows
  • COURSE table – 5 rows
  • COURSE_ACTIVITY table – 6 rows
  • CORP_EXTRACT1 table – 3 rows
  • CORP_EXTRACT2 table – 0 rows

NOTE: In the following steps when writing your queries be sure to list the tables in the FROM clause in the same order they are listed in the instructions. Reversing the order of the tables in the FROM clause will produce an incorrect results set

STEP 4: Using the FULL OUTER JOIN operator

Join the CLIENT and COURSE_ACTIVITY tables using a FULL OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the FULL OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 5: Using the RIGHT OUTER JOIN operator

Join the CLIENT and COURSE_ACTIVITY tables using a RIGHT OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the RIGHT OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 6: Using the LEFT OUTER JOIN operator

Join the CLIENT and COURSE_ACTIVITY tables using a LEFT OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the LEFT OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 7: Using the NATURAL JOIN operator

Join the CLIENT and COURSE_ACTIVITY tables using a NATURAL JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.
  • Will the NATURAL JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 8: Using the INNER JOIN operator

Join the CLIENT and COURSE_ACTIVITY tables using a INNER JOIN.
Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the INNER JOIN be helpful to Ann? Place your response in the lab report document for this step.

Write a conclusion based on the five steps above, which join – if any – should Ann use to populate the spreadsheet that can answer her questions.

STEP 9: Using the UNION operator 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the UNION operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 10: Using the UNION ALL operator

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the UNION ALL operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 11: Using the INTERSECT operator

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the INTERSECT operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 12: Using the MINUS operator

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the MINUS operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 13: Using subqueries

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using a subquery with NOT IN operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

Deliverables
    
What is Due

Submit your spooled lab file with the queries and results sets along with the completed Lab 1 Report to the Dropbox. Your report should contain copies of each query and result set outlined in the lab along with the requested explanation of whether or not it satisfied the business requirement outlined for that particular section of the lab.

31 in stock

SKU: DBM449Week1IA Categories: , ,

Description

GENERAL OVERVIEW
Scenario/Summary
My colleague, Ann Henry, operates a regional training center for a commercial software organization. She created a database to track client progress so she can analyze effectiveness of the certification program. CLIENT, COURSE, and COURSE_ACTIVITY are three of the tables in her database. The CLIENT table contains client name, company, client number, pre-test score, certification program and email address. The COURSE_ACTIVITY table contains client number, course code, grade, and instructor notes. The COURSE table contains the course code, course name, instructor, course date, and location. Although she and her instructors enter much of the data themselves, some of the data are extracted from the corporate database and loaded into her tables.

Loading the initial data was easy. For grade entry at the end of each course, a former employee created a data entry form for the instructors. Updating most client information and generating statistics on client progress is not easy because Ann does not know much SQL. For now, she exports the three tables into three spreadsheets. To look up a grade in the COURSE_ACTIVITY spreadsheet, she first has to look up client number in the CLIENT spreadsheet. While this is doable, it is certainly not practical. For statistics, she sorts the data in the COURSE_ACTIVITY spreadsheet using multiple methods to get the numbers she needs.

Every month, Ann’s database tables need to be refreshed to reflect changes in the corporate database. Ann describes this unpleasant task. She manually compares the contents of newly extracted data from corporate to the data in her spreadsheets, copies in the new values, and then replaces the database contents with the new values.

Ann needs our help. Let’s analyze her situation and determine what advanced SQL she could use to make her tasks easier.
     
L A B O V E R V I E W

Scenario/Summary

The purpose of this lab is to explore join operators to determine which, if any, are appropriate for solving Ann’s business problems, as described in this week’s lecture.

Since Ann prefers to work from Excel spreadsheets, she wants her CLIENT and COURSE_ACTIVITY tables exported into one spreadsheet rather than two, as she is currently using. We need to determine which, if any, of the join operators will provide the data she wants for the single spreadsheet. (Note: we will not perform the export, just determine how to retrieve the necessary data.) Using the spreadsheet, she will be able to determine:

  1. Which course(s) a specific client has taken
  2. What grade(s) a specific client has earned in a specific course
  3. Which clients did not take any courses
  4. Which courses were not taken by any client

Here are results from DESCRIBE commands that show structure (columns and their data types) of tables CLIENT and COURSE_ACTIVITY. You may refer to it while constructing your queries.

SQL*Plus: Release 10.2.0.1.0 — Production on Thu Jun 14 22:38:52 2007

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 — 64bit Production
With the Partitioning, OLAP and Data Mining Options

SQL> desc client

Name

Null?

Type

CLIENT_NO

NOT NULL

CHAR(8)

CLIENT_COMPANY

NOT NULL

VARCHAR2(35)

CLIENT_NAME

NOT NULL

VARCHAR2(35)

CLIENT_EMAIL

 

VARCHAR2(35)

CLIENT_PROGRAM

NOT NULL

CHAR(3)

CLIENT_SCORE

NOT NULL

NUMBER

SQL> desc course_activity

Name

Null?

Type

ACTIVITY_CODE

NOT NULL

CHAR(8)

CLIENT_NO

NOT NULL

CHAR(8)

COURSE_CODE

NOT NULL

CHAR(8)

GRADE

 

CHAR(1)

INSTR_NOTES

 

VARCHAR(50)

SQL>

For this lab you will be creating several documents. First, write your queries in Notepad to create a script file that will contain all of the queries asked for in lab steps 4 through 13. You can (and should) test each query as you write it to make sure that it works and is returning the correct data. Once you have all of your queries written then create a SPOOL session and run your entire script file. Be sure that you execute a SET ECHO ON session command before running the file so that both the query and the output will be captured in the SPOOL file. IMPORTANT: If you are using Windows Vista you will need to create a directory on your C: drive to SPOOL your file into. Vista will not allow you to write a file directly to the C: drive. This will give you two files for the lab. The third file will the be the Lab1 Report document found in Doc Sharing. You will need to put your responses to the questions asked in the various lab steps.

Now let’s begin.

 

L A B S T E P S

 

STEP 1: Start Oracle SQL*Plus via Citrix

 

Log into the Citrix iLab environment. Open your Oracle folder, select SQL Plus and log in to your database instance. Use “sys” as User Name, and “oracle” as the Password. Enter the Host String as “DB9999.world as sysdba” where 9999 is the database number you have been assigned.

STEP 2: Initialize tables

 

Download the pupbld.sql and Lab1_init.sql files associated with the links to your C: drive or to the F: drive in your Citrix environment. You will need to open each of the files and edit the connection string to reflect your instance name. The pupbld.sql file has two connections strings; one at the top of the script and another at the bottom. Be sure to change both of these to reflect your instance name.

Once you have done this then run the pupbld.sql script first (DO NOT copy and paste it) in your SQL*Plus session. The script will create the product_user_profile synonym in the SYSTEM account which will be used each time you log in as a normal user.

Next run the lab1_init.sql script in your session. The script will create a new user (DBM449_USER) that will be used in various labs in this course. You can find the password for this new user by looking at the CREATE USER statement in the script file. Disregard the DROP TABLE error messages. They occur because the script is designed to work regardless of whether you have already created the tables or not. This way, you may run it if you ever decide to resent the contents of your tables to the original values. When you run the script for the first time, the error messages appear as you attempt to drop tables that do not exist.

Once the script has finished you will be logged into the new user and ready to start your lab.

STEP 3: Verify your tables

 

You want to verify that everything completed successfully. To do this execute a SELECT * FROM TAB statement to make sure all 5 tables were created and then you can execute a SELECT COUNT(*) FROM statement using each of the table names. You should find the following numbers of records for each table.

  • CLIENT table – 5 rows
  • COURSE table – 5 rows
  • COURSE_ACTIVITY table – 6 rows
  • CORP_EXTRACT1 table – 3 rows
  • CORP_EXTRACT2 table – 0 rows

NOTE: In the following steps when writing your queries be sure to list the tables in the FROM clause in the same order they are listed in the instructions. Reversing the order of the tables in the FROM clause will produce an incorrect results set

STEP 4: Using the FULL OUTER JOIN operator

 

Join the CLIENT and COURSE_ACTIVITY tables using a FULL OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the FULL OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 5: Using the RIGHT OUTER JOIN operator

 

Join the CLIENT and COURSE_ACTIVITY tables using a RIGHT OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the RIGHT OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 6: Using the LEFT OUTER JOIN operator

 

Join the CLIENT and COURSE_ACTIVITY tables using a LEFT OUTER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the LEFT OUTER JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 7: Using the NATURAL JOIN operator

 

Join the CLIENT and COURSE_ACTIVITY tables using a NATURAL JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.
  • Will the NATURAL JOIN be helpful to Ann? Place your response in the lab report document for this step.

STEP 8: Using the INNER JOIN operator

 

Join the CLIENT and COURSE_ACTIVITY tables using a INNER JOIN.

  • Write and execute the SQL statement that produces the client number and name, course code and grade that the client got in this course.

Will the INNER JOIN be helpful to Ann? Place your response in the lab report document for this step.

Write a conclusion based on the five steps above, which join – if any – should Ann use to populate the spreadsheet that can answer her questions.

 

STEP 9: Using the UNION operator

 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the UNION operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 10: Using the UNION ALL operator

 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the UNION ALL operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 11: Using the INTERSECT operator

 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the INTERSECT operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 12: Using the MINUS operator

 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using the MINUS operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

STEP 13: Using subqueries

 

Examine the clients and courses in Ann’s tables and the CORP_EXTRACT1 table using a subquery with NOT IN operator.

  • Write and execute the SQL statement that examines client numbers in CLIENT and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines client numbers in COURSE_ACTIVITY and CORP_EXTRACT1.
  • Write and execute the SQL statement that examines course names in COURSE and CORP_EXTRACT1.

Which of these statements, if any, will be helpful to Ann? Place your response in the lab report document for this step.

Deliverables

 

 

What is Due

Submit your spooled lab file with the queries and results sets along with the completed Lab 1 Report to the Dropbox. Your report should contain copies of each query and result set outlined in the lab along with the requested explanation of whether or not it satisfied the business requirement outlined for that particular section of the lab.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.