Cis336 all i labs week 1 to week 7 devry university
1. CIS 336 All iLabs Week 1 to Week 7
Devry University
Click this link to get the tutorial:
http://homeworkfox.com/tutorials/general-
questions/4159/cis-336-all-ilabs-week-1-to-week-7-devry-
university/
CIS 336 Week 1 iLab 1 Devry University
LABOVERVIEW
Scenario/Summary
This lab will introduce you to the processes involved in defining one of the key components of a
data model; the relationship diagram (RD). In this lab, you will draw a relationship diagram for
two of the steps shown. Keep in mind when you are trying to decide which side of the
relationship should be the "one" side and which should be the "many" that you must first decide
which side has the primary key, or unique identifier. Once you have decided the primary key of
the relationship, you have identified the "one" side of the relationship. Note that for an RD, the
foreign key "many" side of the relationship points to the primary key "one" side. The "one" side
should have the arrowhead point of the connecting line. This is different than an
entity/relationship diagram (ERD) that we will draw next week, where the "many" side has
crow's feet.
This will familiarize you with how to set up MS Visio to draw database diagrams. Steps 1 - 3
below use the Customer, Order, and Employee tables of a simplified Order Entry database. The
Customer table records clients who have placed orders. The Order table contains the basic facts
about customer orders. The Employee table contains facts about employees who take orders. The
primary keys of the tables are CustNo for Customer, EmpNo for Employee, and OrdNo for
Order.
The following are the TABLE definitions for the first three tables showing the PRIMARY KEY
constraints.
2. TABLE Customer has the following attributes
CustNo NUMBER(5)
CustFirstName VARCHAR2(20)
CustLastName VARCHAR2(30)
CustCity VARCHAR2(30)
CustState CHAR(2)
CustZip CHAR(10)
CustBal NUMBER(12,2)
CustNo is the PRIMARY KEY
TABLE Employee has the following attributes
EmpNo NUMBER(5)
EmpFirstName VARCHAR2(20)
EmpLastName VARCHAR2(30)
EmpPhone CHAR(15)
EmpNo is the PRIMARY KEY
TABLE Order has the following attributes
OrdNo NUMBER(5)
OrdDate DATE
CustNo NUMBER(5)
EmpNo NUMBER(5)
OrdNo is the PRIMARY KEY
Your task for this lab is to create the required relationship diagram for steps 1 and 2 using
Microsoft Visio. Step 3 will require you to analyze the scenario given and present your own
resolution to the question. Step 4 is an individual assignment that will introduce you to the group
project and the process of identifying entities and attributes. When finished with the lab, you
should have a complete diagram using all 5 entities, a written explanation for #3, and two lists
(entities and attributes) for Step 4.
Deliverables
The deliverable for this lab is a single MS Word document named "Lab1_solution_yourname"
with the diagram for problems 1 and 2, the written answer for the question in Step 3, and the lists
of entities and attributes for the Initial Project Exercise (Step 4). You should copy and paste the
diagram from MS Visio into a Word document and use this document for Steps 3 and 4.
3. LABSTEPS
STEP 1: Drawing your first ER diagram Title
Identify the foreign key columns in the table structures above and draw a relationship diagram
depicting the relationships between the tables. In the Order table , the CustNo column references
the Customer table and the EmpNo column references the Employee table. For each relationship,
identify the table on the "1" side of the relationship and the table on the "Many" side.
STEP 2: Extending the ER diagram
Extend your relationship diagram from problem 1 by adding two tables (OrdLine and Product).
Table definitions for the table structures and primary keys constraints are shown below. You will
need to identify the FOREIGN KEY(s) to complete this problem. When finished you should
have a total of 5 tables represented in your diagram for this problem. To copy and paste the
diagram into Word, select Edit from the menu and then Copy Diagram. Open a Word document
and use CTRL-V to paste the diagram.
TABLE Product has the following attributes
ProdNo CHAR(8)
ProdName VARCHAR2(20)
ProdNo is the PRIMARY KEY
TABLE OrdLine has the following attributes
OrdNo CHAR(8)
ProdNo CHAR(8)
Qty NUMBER(5)
The combination of OrdNo and Prodno is the PRIMARY KEY
STEP 3: Should a NULL be allowed?
From examination of the sample data and your current understanding of businesses in which
orders could be placed either in person, over the phone, or over the Internet, determine if it
would be permissible for null values to be allowed for the foreign key EmpNo in the Order table.
This column would reference back to the EmpNo column in the employee table. Why or why
not?
4. OrdNo OrdDate CustNo EmpNo
O1656777 02/11/2000 C8543321
O7959898 02/19/2000 C8543321 E8544399
STEP 4: Initial Project Exercise
Although the overall project itself will be done as a group, this first exercise is designed as an
individual effort and is intended to; (1) get you to read the project specifications, and; (2)
introduce you to the first step in designing a database from scratch. This little exercise will have
you see how many entities and attributes you can find in the project specifications. In week three,
you will work with your assigned project team and compare notes on what you have found. This
is not rocket science here so remember, you are looking for people, places, things, and events
(entities) and the attributes that describe them.
CIS 336 Week 2 iLab 2 Devry University
Lab two introduces the next step in creating a data model, the Entity Relationship Diagram
(ERD). You will be given a business scenario for a company named Clapham Specialty Store,
which is a small specialist grocery and delicatessen. The business specifications will outline a
number of things about the business, some of which will apply directly to the database you are
being asked to model. There is a table which lists the entities (tables) that will be needed for the
database and related attributes (columns) for each entity. There is also a column that lists specific
information about the entity that will be helpful in determining its relationship to other entities
within the model.
Be sure to include the minimum and maximum occurrences of each relationship (cardinality) and
to supply a name to the relationship that will work in both directions. If there is not a single word
that will apply, then supply a separate name for each direction of the relationship.
Narrative/Case Study
The Clapham Specialty Store is a small, specialist grocery and delicatessen. A new owner, John
Balfour, who would like to expand the store and improve its profits, has recently purchased the
store. The store sells general groceries, wines and liquors, and has a small deli counter. The store
is open from 5:00 a.m. to 12:00 midnight. Many of the customers are repeat customers who
come in to buy products they forgot from their regular grocery shopping expedition at the
supermarket.
The store sells about 3,000 different products ranging from toilet cleaner to 2 oz. jars of caviar,
and champagne to liverwurst. Each product is displayed on a shelf on one side or the other of the
aisle. The products arrive and their details (cost, quantity, SKU number, package size, purchase
5. date) are recorded in the back room before they are displayed. The new owner wants to know
which products the store sells most of and which are the most profitable.
The following is some general information about the company and its current processes.
The store has 3 cash registers.
Between 3 and 7 employees will work at any given time, depending on the time of day and how
busy they are.
An employee logs in to the register at the start of a shift and logs out at the end.
The name, address, Social Security number and other information is recorded for every
employee.
All employees are paid weekly against an hourly rate which varies depending on their job
description.
Each sale is identified by a Receipt No. and a timestamp (date and time) and consists of sale
items with a quantity and price recorded for each product.
As a convenience for known customers, they offer a local delivery service. Deliveries are only
made to customers who are registered at the store; walk-ins must record their name, address, and
phone number before a delivery can be made to them.
John can find the cost of the goods from the accounts system. What John would like to have is a
point of sale system (POS) that records what has been sold to whom, by whom, for how much,
and when. Also, he needs to be able to record the delivery trips that are made, who makes the
delivery, how long the delivery takes, and the amount of the sale. There is concern at this point
that the cost of delivering the sales to customers is not worth the return on investment.
Requirements:
You have been asked to develop a logical data model for Clapham Specialty Store based on the
information given to you by John and his staff. Through analysis of the nouns and verbs in the
case study above, you have accumulated the following entity, attribute, and relationship
information shown in the table below. The attribute list may not be complete. If you determine
that additional attributes are needed to better define an entity then you should add them.
Entities Attributes and Relationships for Clapham Store:
Entity
Attributes
Relationships
6. Employee
ID Number, Last Name, First Name, Phone Number, Employee Type ID
An Employee can belong to any one of the three job categories, but can belong to one and only
one of the three. Employees have names and other contact information.
Employee Type
Type ID, Description, Hourly Pay Rate
An employee can be either a clerk, delivery person, or a supervisor.
Register Log
Register Log Number, Register Number, Log In Time, Log Out Time, Employee ID
Sales are made using a register and can be tracked by the register log number. An employee must
log into the register before he/she can use it and must log out when finished with a shift at that
register. An employee may use more than one register during a period of work.
Register
Register Number, Register Location Description, Register Serial Number
The store has 3 registers: One located at the back of the store and two located at the front of the
store; one on the left and one on the right of the entrance.
Deliveries
Delivery Number, Employee ID, Sales Receipt Number, Time the Employee Left and Returned
Relates to both the employee and the sale entities. This entity will help track deliveries. An
employee can make many deliveries but a sale is delivered by one and only one employee.
Location
Location ID, Aisle, Side, Shelf
Relates to product and identifies one or more areas of the store where products are displayed.
7. Product
Product ID, Name, Package Size, Cost, Quantity on Hand (QOH), Last Purchased Date, Reorder
Minimum
Identifies the products the store sells. One or more products can be sold per sale. The quantity
on hand allows John to determine his inventory levels. The reorder minimum can be used to
determine when the inventory level has reached a reorder point.
Sale
Receipt Number, Sales Amount, Sale Date- Time
A sale is identified by a single receipt. Sales are:
made to one or more Customers but only one customer at a time.
made by one or more Register Clerks but only one clerk per sale.
recorded on one or more Registers but only one register per sale.
delivered by one or more delivery persons but no one sale can be delivered by more than one
delivery person.
Sold Items
Receipt Number, Product ID, Item Price, Quantity Sold
Sale Item is part of sale and records product sold per sale. Sale item must be able to associate
multiple products sold on a single sales receipt.
Customer
Customer Number, First Name, Last Name, Address, Phone Number
8. A customer can be associated with multiple sales, but any one sale is to one and only one
customer. A sale can occur without a customer registering in the system.
Using MS Visio, develop an ERD that meets the following guidelines:
Draw the entities with their attributes.
Indicate the relationships between the entities using Crow's Foot notation. You will need to
determine the cardinality and optionality for each direction of the relationships. Some of the
Foreign Key relationships are identified in the graph above but not all. Be sure you identify and
account for all Foreign Key relationships.
Add a name (in both directions) to the relationships. Remember, if you can verbalize the
relationship in both directions then you probably have a valid relationship.
Deliverables
The deliverable for this lab will be your completed ERD as a single MS Word document using
copy/paste from the MS Visio application and named "lab2_solutions_yourname".
LABSTEPS
STEP 1: Drawing entities and attributes
9. Be sure to include all of the entities that have been defined. You need to include at least the
primary and foreign key attributes where applicable in your diagram.STEP 2: Indication of all
relationships
Be sure that you link all entities based on PK to FK relationships. There may be a case where
you need to identify a combination PK and if so make sure that all of the relationships involved
are defined. Be sure that you have set your Visio editor to show Crow's Foot notation. Also, be
sure that you are defining the correct cardinality for the relationships.
STEP 3: Naming of relationships
Do not accept the default naming convention for your relationships in all cases. There may be
some relationships where this is applicable, but in most cases you will want to explicitly name
the relationship. Be sure that you have provided a verb phrase for both directions in the
relationship.
This is the end of lab #2
CIS 336 Week 3 iLab 3 Devry University
Beginning with this lab, and continuing through the remaining weeks you will be doing all of
your work in Oracle itself. The editor interface to the Oracle server is SQL*Plus, and by now
you have received your logon ID and password and should have at least made sure you can
connect. If for any reason you have not done so, please do so now before continuing any further.
If for any reason you cannot connect then you need to let the instructor know ASAP so that any
problems can be resolved.
Before attempting Lab #3, you need to be sure you have read through the SQL*Plus
tutorial which can be found in Doc Sharing as well as under the SQL*Plus Tutorial tab in Week
3. This tutorial describes the functionality of the editor and will take you through the process of
setting up and using the SQL*Plus in the iLab environment so that it will best serve your needs
for the remainder of the labs required for this course.
The lab for this week addresses taking a logical database design (data model) and now
transforming that into a physical model (tables, constraints, and relationships). As part of the lab,
you will need to download the Zip file titled "Lab 3 Support Documents" from Doc Sharing.
This Zip file contains three documents: Lab 3 Relationship Diagram.docx, Lab 3 Meta Data
Diagram.xlsx, and Lab 3 Input Data.docx.
Your job will be to take the meta data defined in the data dictionary spreadsheet document, and
using the relationship diagram as a guide define the table structures and constraints using both
CREATE TABLE and ALTER TABLE statements. Once this has been done, you will need to
write the INSERT INTO TABLE statements to insert the data provided into the table. The data
10. should verify that the constraints you have created are valid and define the correct referential and
data integrity constraints asked for. Lastly, you will write SELECT statements to query the tables
and verify the data was populated.
Narrative/Case Study
For this lab, you be working with command-line SQL to build a series of relational tables, using
SQL CREATE statements in a script file format for the Student Database and then populate
those tables through the use of INSERT statements with sample data.
You will need to create a script file and name it YourName_Lab3.txt containing the following
code:
1. The drop table statements listed later in the specifications of this lab.
2. The CREATE TABLE statements required to build the seven (7) tables.
3. The INSERT statements necessary to insert all of the sample data.
4. Seven select statements to verify that the data is in the tables and accessible.
To help you accomplish this task successfully, you are being supplied with the following three
documents which can be found in the Doc Sharing tab on the course website:
1. A Relationship Diagram of the database showing in graphical form the 1:M relationships
between the tables (336_Lab3_Relationship_Diagram.doc).
2. A Meta Data chart providing information about table names, column names, etc. Be sure
to follow this reference exactly when constructing your CREATE TABLE statements
(336_Lab3_Data_Dict.xls).
3. A listing of sample data to use when writing the INSERT statements to populate the
tables (336_lab3_input_data.doc).
The following guidelines are being provided to help assist you in creating your script file:
• Create the tables in the order shown in the data dictionary. Use the names for the tables
and columns as listed in the Meta Data chart – Do not change them as it will affect your
grade.
• Creating CONTRAINTS -
• Create all constraints as indicated in the data dictionary.
• Constraint suffixes must be as follows:
• Primary key constraint – PK
• Foreign key constraint – FK
• Check constraint - CC
11. Explicitly name all constraints PRIMARY KEY, FOREIGN KEY, and CHECK constraints to
reflect:
• TableName_ColumnName_ConstraintSuffix (For example, to name a PRIMARY KEY
constraint on the SID column in the student table you would use STUDENT_SID_PK.)
• For this lab you do not have to explicitly name NOT NULL constraints
Create all PRIMARY KEY and NOT NULL constraints within the CREATE TABLE statements
at the column level (line level), unless the Primary Key is a composite Primary Key (yes, there is
one). Composite Primary Key constraints must be created at the table level. Create all FOREIGN
KEY and CHECK constraints at the table level using ALTER TABLE statements. All constraints
must be added prior to populating the tables with data. Create all of the tables and all of the
constraints before populating any of the tables with data. Insert statements must be in the same
order as the tables are created (follow the order in the sample data file). ALL character strings
must be enclosed in single quotes. This includes alpha strings and alphanumeric (remember that
any formatting within a numeric strings makes it alphanumeric). If you are inserting a NULL, do
not enclose the word NULL in single quotes, as this will insert the word NULL into the row. To
insert a null you simply use the word NULL.
Deliverables
The deliverable for this lab will include the following documents.
1. Your script file. Create this file in Notepad not Word. Make sure your name is in a
comment area at the top of the script file. Use a double dash to create a one line
comment:
--Jacob Smith
--Lab 3
1. Your lab output file created using a spool session in SQL*Plus.
Be sure to use the SET ECHO ON session command when creating the output file so that both
the SQL commands and results will show in the output. Be sure your name is on all documents
and that all documents have been included in a single Zip file for this week’s assignments.
LABSTEPS
STEP 1: The DROP statements
The following DROP TABLE statements must appear at the top of your script file. This will
allow you to run and re-run your script file as often as you need to. The first time you run your
script file you will get an ERROR on the drop statements saying the Table or View does not
12. exist. This is true since it has not been created yet, but the error is more informational than
anything. Once the tables are created, you will not get this error again.
DROP TABLE ENROLLMENT CASCADE CONSTRAINTS PURGE;
DROP TABLE COURSE_SECTION CASCADE CONSTRAINTS PURGE;
DROP TABLE COURSE CASCADE CONSTRAINTS PURGE;
DROP TABLE TERM CASCADE CONSTRAINTS PURGE;
DROP TABLE STUDENT CASCADE CONSTRAINTS PURGE;
DROP TABLE FACULTY CASCADE CONSTRAINTS PURGE;
DROP TABLE LOCATION CASCADE CONSTRAINTS PURGE;
STEP 2: The CREATE TABLE statements
Next, define the CREATE TABLE statements for the seven tables that you are to create based
upon the ERD and Data Dictionary that you have been given for this lab. Be sure to follow the
guidelines given above on how and where to create the different types of constraints for each
table.
STEP 3: The INSERT statements for the data
The third step is to create the insert statements to insert the sample data into the tables created in
Step 2. You might find it helpful to take the Word document containing the sample data and save
it as a text file. After doing this, you could create the insert statements around the actual data that
is in that file. The process for doing this should have been covered in one of the lectures for this
unit. If it was not, then ask your instructor to discuss this process with the class.
STEP 4: The SELECT statements
The next step of the lab will be to create the select statements to verify the data was inserted
correctly. You should have seven select statements; one for each table. The command is
SELECT * FROM Table_Name; For example, to select all columns from the Student table, the
command would be SELECT * FROM Student;
Be sure to save all of the above statements in your script file.
STEP 5: Testing and verifying your script
Now we come to the point of verifying that your script file works by creating all of the tables and
inserting all of the data. To verify this you will need to execute your saved script file and create
an output file to capture the results being returned to the session by using the spool COMMAND
outlined in the tutorial "Using Oracle SQL*Plus." This output file will be one of the files you
will be turning in for grading.
CIS 336 Week 4 iLab 4 Devry University
13. Lab 4 of 7: Building the Physical Model (28 points)
Submit your assignment to the Dropbox located on the silver tab at the top of this page. For
instructions on how to use the Dropbox, please click here.
(See Syllabus/"Due Dates for Assignments & Exams" for due dates.)
LABOVERVIEW
Scenario/Summary
Lab #4 will introduce the various aspects of the SQL select statement and the methods of
retrieving data from the database tables. The lab will utilize a set of tables found in the script file
(LeeBooks.sql) found in the Doc Sharing area of the website. You will need to download the file,
then run the script in your SQL*Plus session. These tables will be used for the remaining labs in
this class.
The SELECT statement is the primary means of extracting data from database tables, and allows
you to determine exactly which data you want to extract by means of different comparison
operators used in the WHERE clause. This includes the use of specific "wild card" characters
which allow you to search for character or number patterns within the data. You can also
perform mathematical expressions within the SELECT statement to create derived output. The
ORDER BY clause allows you to sort the output data in either ascending (the default) or
descending order. Lab #4 will explore all of these applications of the SELECT statement.
General Lab Information and Considerations
Each query in the script file you will create must be numbered (use - -1 comments for
numbering) and listed in order. The SQL for the following exercises should be written using
Notepad and run in SQL*Plus. Read each problem carefully and follow the directions as stated.
A Clean Script File:
A script file is meant to be like a program. The file can be run every time the code needs to be
executed without having to retype the code again each time. For this reason, it is important that
there are no errors in the code inside the file. You can go back and forth between Notepad and
Oracle when creating your script file to check your queries and verify if they work or not, but
you do not want to create your final output file until after you have verified that everything in
your script is correct by running it, in its entirety at least once and viewing the output. Once this
has been done, you can create your final output file, with echo on to create the document you can
turn in with your lab. Remember in using a spool session, you must type "SPOOL OFF" at the
SQL> prompt after your script stops spooling to capture all of your data!
Lab Do's and Don’t's
Do Not include the LEEBOOKS.SQL as part of your lab script.
14. Do use Notepad to write your query script file.
Do Not write your queries in Word.
Do test each query before moving on to the next.
Do Not include extra queries for a problem unless the problem explicitly asks for more than one
query.
Do test your queries before creating your final output file.
Do Not turn in a script file that has queries with errors.
Do number each query using - -1 comment notation.
Do Not start your query on the same line as the comment.
Do remember to check your final output and script file for accuracy.
Do Not turn in your lab without first checking your output file to verify that it is correct.
Things to keep in mind:
If you are not sure of the table names in your user schema, you can use the following select
statement to list them.
SELECT * FROM TAB;
If you want to know the name of the columns in a particular table, you can use the following
command to list them.
DESC
Making a script file containing a series of describe statements for each table and then spooling
the output will give you a listing of all the tables with column names.
Be sure to review and verify your final output when you are finished. DO NOT assume anything.
Write queries for each of the stated problems in the steps below that will return a result set of
data to satisfy the requirements. When finished, your script file should have a total of 13 queries
and your resulting output file should show both the query and result set for each.
Deliverables
The deliverable for this lab will include:
15. Your script file with the 13 queries in it. Be sure your name, course number, and lab number are
in a comment area at the top of your file.
An output file created using SET ECHO ON showing both the SQL code and the results.
Both documents are to be zipped into a single file before submitting to the iLab Dropbox for
Week 4.
LABSTEPS
STEP 1:
Using the BOOKS table, write a query that will list the categories for the books in inventory. List
each category only once in your result set.
STEP 2:
Using the BOOKS table, write a query that will list the title and publisher ID for each book in the
table. Use the column heading of "Publisher ID" for the pubid field.
STEP 3:
Using the BOOKS table, write a query that will list the book title, retail price, and the amount of
markup for each book. The amount of markup is the retail price minus the cost. Use the column
heading “Price Markup” for the arithmetic expression column.
STEP 4:
Using the BOOK_CUSTOMER table, write a query that will list the customer’s first name, last
name, and city for those customers living in zip code 31206.
STEP 5:
Using the BOOK_ORDER table, write a query that will list everything about the orders placed
prior to April 2, 2009.
STEP 6:
Using the BOOK_ORDER table, write a query that will list everything about the orders that have
not been shipped yet.
STEP 7:
Using the BOOK_CUSTOMER table, write a query using the AND and OR operators that will
list the customer information for those customers living in either Florida or New Jersey who
have not been referred by another customer.
16. STEP 8:
Using the BOOKS table, write a query that will list all information about those books that are not
computer books and do not cost more than $30.00 retail.
STEP 9:
Using the AUTHOR table, write a query that will list all information about authors whose first
name ends with an “A”. Put the results in descending order of last name, and then ascending
order by first name. This should be done using a single query.
STEP 10:
Using the BOOK_ORDER table, write a query using the > and < operators that will list the
orders that were placed between April 1, 2009 and April 4, 2009. Only show the orders for April
2nd and 3rd in your result set.
STEP 11:
Using the BOOK_ORDER table, write a query that will list the orders that were placed between
April 2, 2009 and April 4, 2009 including those placed on the 2nd and 4th. Use a different
approach (operator) in writing this query than used in the query for #10, that is, do not use > and
< signs in your query.
STEP 12:
Using the BOOKS table, write a query that will list the book title, publisher ID, and published
date for all books that were published by publisher 4 or after January 1, 2001. Order the results in
ascending order by publisher ID and give the publish date and publisher ID columns meaningful
titles.
STEP 13:
Many organizations use percentage of markup (e.g., profit margin) when analyzing financial
data. To determine the percentage of markup for a particular item, simply subtract the cost for
the item from the retail price to obtain the dollar amount of profit, and then divide the profit by
the cost of the item. The resulting solution is then multiplied by 100 to determine the percent of
markup. Using a SELECT statement, display the title of each book and its percent of markup.
For the column displaying the percent of markup, use “Markup %” as the column heading.
This is the end of lab #4
CIS 336 Week 5 iLab 5 Devry University
17. Lab 5 of 7: Retreiving data from Multiple Tables (28 points)
Submit your assignment to the Dropbox located on the silver tab at the top of this page. For
instructions on how to use the Dropbox, please click here.
(See Syllabus/"Due Dates for Assignments & Exams" for due dates.)
LABOVERVIEW
Scenario/Summary
Lab 5 deals with writing queries using multiple tables as covered in the reading and lecture
material this week. In some cases, you will be given the option to write a query using either the
TRADITIONAL method of joining tables or using the JOIN key word. In some cases, you will
be asked to use a specific approach. Using the incorrect process when the process is specified
will result in points being taken off for that problem.
The SELECT statement is the primary means of extracting data from database tables, and allows
you to determine exactly which data you want to extract by means of different comparison
operators used in the WHERE clause. This includes the use of specific "wild card" characters
which allow you to search for character or number patterns within the data. You can also
perform mathematical expressions within the SELECT statement to create derived output. The
ORDER BY clause allows you to sort the output data in either ascending (the default) or
descending order. Lab #5 will explore all of these applications of the SELECT statement.
General Lab Information and Considerations
This lab will utilize a set of tables found in the script file (LeeBooks.sql) found in the Doc
Sharing area of the website. If you have not yet downloaded this file from Doc Sharing then do
so now. Once you have downloaded the script file, import and run the script in SQL*Plus.
Each query in the script file you will create must be numbered (use --1 comments for numbering)
and in order. The SQL for the following exercises should be written using notepad and run in
SQL*Plus.
A Clean Script File:
A script file is meant to be like a program. The file can be run every time the code needs to be
executed without having to retype the code again each time. For this reason, it is important that
there are no errors in the code inside the file. You can go back and forth between Notepad and
Oracle when creating your script file to check your queries and verify if they work or not, but
you do not want to create your final output file until after you have verified that everything in
your script is correct by running it, in its entirety at least once and viewing the output. Once this
has been done, you can create your final output file, with echo on to create the document you can
turn in with your lab. If using a Spool Session, be sure to type "SPOOL OFF" AT THE SQL>
after your Script Stops Spooling!
18. Lab Do's and Don’t's
Do Not include the LEEBOOKS.SQL as part of your lab script.
Do use Notepad to write your query script file.
Do Not write your queries in Word.
Do test each query before moving on to the next.
Do Not include extra queries for a problem unless the problem explicitly asks for more than one
query.
Do test your queries before creating your final output file.
Do Not turn in a script file that has queries with errors.
Do number each query using --1 comment notation.
Do Not start your query on the same line as the comment.
Do remember to check your final output and script file for accuracy.
Do Not turn in your lab without first checking your output file to verify that it is correct.
Things to keep in mind:
If you are not sure of the table names in your user schema, you can use the following select
statement to list them.
SELECT * FROM TAB;
If you want to know the name of the columns in a particular table, you can use the following
command to list them.
DESC
Making a script file containing a series of describe statements for each table and then spooling
the output will give you a listing of all the tables with column names.
Be sure to review and verify your final output when you are finished. Do Not assume anything.
Write queries for each of the stated problems in the steps below that will return a result set of
data to satisfy the requirements. When finished, your script file should have a total of 13 queries
and your resulting output file should show both the query and result set for each.
19. Deliverables
Submit for grading:
Your script file with the 13 queries in it. Be sure your name, course number, and lab number are
in a comment area at the top of your file. Submitting ONLY your spooled output will result in a
10-point deduction.
An output file created using SET ECHO ON showing both the SQL code and the results.
Both documents must be zipped into a single file before submitting to the iLab Dropbox for
Week 5.
LABSTEPS
STEP 1:
Using the BOOKS and PUBLISHER tables, create a query using the traditional join method that
will return a list containing the book title, publisher contact person, and publisher phone number
for all publishers whose publisher name starts with an ‘R’.
STEP 2:
Using the DUAL table, create a query that will return the day of the week, hour, minutes, and
seconds of the current date setting on a computer. The day should be in all upper case.
STEP 3:
Using the BOOK_CUSTOMER and BOOK_ORDER tables, create a query using the
NATURAL JOIN method that will return a list containing the customer first name and last name
and the order number for all orders that have been shipped. Give the customer name column an
alias of "Customer Name" and order the output by the customer number in the BOOK_ORDER
table in ascending order.
STEP 4:
Using the BOOK_ORDER table, create a query that will return the order number, order date,
shipping address, city, state, and zip code for all orders going to Atlanta or Austin. Format the
order date to display as Month DD, YYYY and give the column an alias of "Date Ordered". Be
sure the month begins with a capital letter.
STEP 5:
Using the BOOK_ORDER table, create a query using the correct function to return the order
number, the date ordered, the date shipped, and a column representing the number of months
between the two dates for all columns where a date shipped exists. Format the number returned
20. from the function to display only two decimals, and give the column an alias of "Months
Between".
NOTE: Be sure that all of the numbers in the fourth column are positive numbers.
STEP 6:
Using the correct tables in your schema, create a query using either join operation that will list
the title of each book and author name(s). Give the title column an alias of "Book Title". Sort the
results by title and then by author last name.
STEP 7:
Using the BOOKS table, create a query that will return the book title, cost, and retail price for all
books with a title starting with the letter ‘H’. Use the correct conversion function to format the
cost and retail columns to show dollars and cents with a dollar sign (e.g., a price of $25 would
display $25.00 in the result set).
STEP 8:
Using the BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a query using an
OUTER JOIN operation that will list the book title, order date, and order number for all books in
the BOOKS table. Order your output in descending order by ORDER_ITEMS.BOOKID. There
are three books that have never been ordered which should show up at the top of your listing.
STEP 9:
Using the correct tables, create a query using the traditional join operation that will list the
customer first and last name, book title, and order date (formatted as MM/DD/YYYY with an
alias of “Order Date”) for all the customers who have purchased books published by 'PRINTING
IS US'.
STEP 10:
Using the BOOKS and ORDER_ITEMS table, write a query using the correct Relational Set
Operator that will show all of the Book IDs in the BOOKS table that have not been ordered.
STEP 11:
Using the BOOK_CUSTOMER, BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create
a query using traditional join conditions based on comparisons between primary and foreign keys
that will list the customer number, first and last name, and book title. Limit your listing to only
those books in the ‘FITNESS’ category.
STEP 12:
21. Using the BOOKS, ORDER_ITEMS, and BOOK_ORDER tables, create a query that will list the
title, retail, quantity, and order date for all books ordered after April 30, 2009.
STEP 13:
Using the correct tables, create a query using either join operation you wish that will list the
order id, order date, quantity ordered, and retail price for every book that has been ordered.
Format the date as MM/DD/YYYY with an alias of “Order Date” and format the retail price
column using the correct function to show dollars and cents with a dollar sign ( $ ) and a column
alias of “Retail”.
This is the end of lab #5
CIS 336 Week 6 iLab 6 Devry University
Lab 6 of 7:
Oracle Single Row and Group Functions (28 points) Lab #6 will introduce the various aspects of the
Single-Row and Group Functions available in the Oracle Database. Most functions can be used in either
the SELECT statement or the WHERE clause, but more commonly are used in the SELECT. Chapters 5 and
6 cover most all of the normal processing you use in these functions. In some cases, you will be asked to
used more than one function within a single SELECT statement. General Lab Information and
Considerations This lab will utilize the same set of tables found in the script file (LeeBooks.SQL) that
were used for Labs 4 and 5. Each query in the script file you will create must be numbered (use --1
comments for numbering) and in order. The SQL for the following exercises should be written using
notepad and run in SQL*Plus. Read each problem carefully and follow the directions as stated. A Clean
Script File: A script file is meant to be like a program. The file can be run every time the code needs to be
executed without having to retype the code again each time. For this reason, it is important that there
are no errors in the code inside the file. You can go back and forth between notepad and Oracle when
creating your script file to check your queries and verify if they work or not. However, you do not want
to create your final output file until after you have verified that everything in your script is correct by
running it, in its entirety at least once and viewing the output. Once this has been done, you can create
your final output file, with echo to create the document, you can turn in with your lab. Remember in
using a spool session, you must type "SPOOL OFF" at the SQL> prompt after your script stops spooling to
capture all of your data! Lab Do's and Don’t's * Do Not include the LEEBOOKS.SQL as part of your lab
script. o Do use Notepad to write your query script file. * Do Not write your queries in Word. o Do test
each query before moving on to the next. * Do Not include extra queries for a problem unless the
problem explicitly asks for more than one query. o Do test your queries before creating your final output
file. * Do Not turn in a script file that has queries with errors. o Do number each query using - -1
comment notation. * Do Not start your query on the same line as the comment. o Do remember to
check your final output and script file for accuracy. * Do Not turn in your lab without first checking your
output file to verify that it is correct. Things to keep in mind: If you are not sure of the table names in
your user schema, you can use the following select statement to list them. SELECT * FROM TAB; If you
22. want to know the name of the columns in a particular table you can use the following command to list
them. DESC Making a script file containing a series of describe statements for each table and then
spooling the output will give you a listing of all the tables with column names. Be sure to review and
verify your final output when you are finished. Do Not assume anything. Write queries for each of the
stated problems in the steps below that will return a result set of data to satisfy the requirements.
When finished, your script file should have a total of 13 queries, and your resulting output file should
show both the query and result set for each. Deliverables Submit for grading: 1. Your script file with the
13 queries in it. Be sure your name, course number, and lab number are in a comment area at the top of
your file. 2. An output file created using SET ECHO ON showing both the SQL code and the results. 3.
Both documents are to be zipped into a single file before submitting to the iLab Dropbox for Week 6
Week 6. L A B S T E P S
STEP 1: Back to top Using the BOOK_CUSTOMER table and the NVL function, create a query that will
return a list containing the customer number, first name, last name, and the characters ‘NOT REFERRED’
if the customer was not referred by another customer. Give the derived column an alias of REFERRED
BY. Do not list any customers that were referred by another customer.
STEP 2: Back to top Using the BOOKS table and the SUBSTR function, create a query that will return a list
of book ISBN codes and the book title for all the computer books. Format the ISBN code to display as 9-
999-99999-9 (e.g., 1059831198 would display as 1-059-83119-8)
STEP 3: Back to top Using the BOOKS table, create a query using the correct functions to return the
category name, the total retail of all books per category with a column alias of "Total Retail", and the
average retail of all the books per category with an alias of "Average Retail" for all categories with a total
retail greater than $40.00. Format the total retail and average retail columns using the correct function
to show dollars and cents with a dollar sign.
STEP 4: Back to top Using the correct tables in your schema, create a query using either join operation
you wish that will list the book title and number of authors for all books that have been written by more
than one author. Give the title column an alias of "Book Title" and the column showing the number of
authors an alias of "Number of Authors".
STEP 5: Back to top Using the BOOK_AUTHOR and AUTHOR tables for the upper most query, create a
sub query that will return the BOOKID, and the first and last name of the author(s) who have written the
book(s) that have been purchased the most. To successfully accomplish this, you will need to first find
out the maximum total number of copies (based on quantity) sold of a book (based on bookid) in the
ORDER_ITEMS table. This will be done in the bottom most query. The return from this query will be used
to compare against the BOOKID in the ORDER_ITEMS table that occurs an equal number of times in the
middle query. The return of this query will then be used to compare to a BOOKID related to an Author in
the tables of the top most query. (HINT: Be careful, you will need both GROUP BY and HAVING clauses
for your solution.)
23. STEP 6: Back to top Using the correct tables, create a sub query using either join operation you wish that
will list the customer number, first and last name concatenated together, and city for all customers who
have placed an order for the most expensive book (based on retail price). Give the combined customer
names column and alias of "Customer Name".
STEP 7: Back to top Using the ORDER_ITEMS table, create a query using the correct functions to return
the item#, the total quantity of items ordered with an alias of "Total", the average quantity per order
with an alias of "Average" (since averages are often in decimals, only show two decimal places), the
minimum quantity ordered with an alias of "Minimum", and the maximum quantity ordered with an
alias of "Maximum". Your output results set should have five columns and four rows of data.
STEP 8: Back to top Using the BOOKS table, create a query using the DECODE function that will display
the book title, the published date, and the publisher name (this is where the decode function comes in).
Give the publisher name column an alias of "Publisher Name", and order the publisher names in
descending order. The publisher names used should be the same as those in the PUBLISHER table. DO
NOT join to the Publisher table for this query.
STEP 9: Back to top Using the PUBLISHER table, create a query that will return a line of output like the
one below for each record in the table. Be sure to use the correct functions in the SELECT statement, so
that your output looks like the example below. The contact person for Printing Is Us Publishing is
Tommie Seymour. Be sure to use the correct function to display the publisher name and publisher
contact with only the first letter of each word capitalized.
STEP 10: Back to top Using the correct tables, create a query using the JOIN ON method to display a
listing of all customers who have purchased more than two books. List the customer’s last name, the
customer’s city and state, and the number of books they have purchased. Give the number purchased
column and alias of "Number Purchased".
STEP 11: Back to top Using only the BOOK table for the upper most statement, create a sub query that
will update the retail price of all books published by PRINTING IS US by five percent (retail * 1.05).
Remember, all you have is the publisher "name". Use the sub query to find the publisher ID. To verify
your update, provide a select statement on the BOOKS table before your update statement, and then a
second select on the BOOKS table after the update. Once you have verified the results, you can issue a
ROLLBACK statement to return the data to the original state.
STEP 12: Back to top Using the BOOK_CUSTOMER table, write a sub query that will return the names of
those customers who were referred by the same individual who referred Jorge Perez. Do not display
Jorge Perez’s name in the returned results (Hint: you should only have two customers displayed and the
exclusion for Jorge Perez must be associated with the upper query).
STEP 13: Back to top Using the BOOKS table, create a query using the correct functions to return the
category name, total number books per category with a column alias of "Category Total", and the total
cost of all the books per category with an alias of "Cost". Format the cost column using the correct
function to show dollars and cents with a dollar sign. This is the end of Lab #6 Back to top]HTML
24. CIS 336 Week 7 iLab 7 Devry University
LABOVERVIEW
Scenario/Summary
There is a lot more to a database than just tables and the data in them. A very important part of
database security has to do with using and understanding Database Views. Being able to enhance
the efficiency of the database tables by using additional indexes is also a very important aspect of
database development. Finally, being able to create and use Database Sequences to automate
some of the sequential processes in the database can not only save time but improve efficiency.
In Lab 7, you will have a chance to work with all three of these areas.
General Lab Information and Considerations
This lab will utilize the same set of tables found in the script file (LeeBooks.SQL) that were used
for Labs 4 through 6.
Each query in the script file you will create, must be numbered (use either –1 or REM 1
comments for numbering) and in order. The SQL for the following exercises should be written
using notepad and run in SQL*Plus. Read each problem carefully and follow the directions as
stated.
A Clean Script File:
A script file is meant to be like a program. The file can be run every time the code needs to be
executed without having to retype the code again each time. For this reason, it is important that
there are no errors in the code inside the file. You can go back and forth between notepad and
Oracle when creating your script file to check your queries and verify if they work or not.
However, you do not want to create your final output file until after you have verified that
everything in your script is correct by running it in its entirety at least once and viewing the
output. Once this has been done, you can create your final output file, with echo on to create the
document, you can turn in with your lab. Remember in using a Spool Session, you must type
"SPOOL OFF" at the SQL> PROMPT after your Script stops spooling to capture all of your
data!
Lab Do's and Don't's
Do Not include the LEEBOOKS.SQL as part of your lab script. Do use Notepad to write your
query script file.
Do Not write your queries in Word.
25. Do test each query before moving on to the next.
Do Not include extra queries for a problem unless the problem explicitly asks for more than one
query.
Do test your queries before creating your final output file.
Do Not turn in a scrip file that has queries with errors.
Do number each query using either --1 or REM 1 comment notation.
Do Not start your query on the same line as the comment.
Do remember to check your final output and script file for accuracy.
Do Not turn in your lab without first checking your output file to verify that it is correct.
Things to keep in mind:
If you are not sure of the table names in your user schema, you can use the following select
statement to list them.
SELECT * FROM TAB;
If you want to know the name of the columns in a particular table, you can use the following
command to list them.
DESC
Making a script file containing a series of describe statements for each table and then spooling
the output will give you a listing of all the tables with column names.
Be sure to review and verify your final output when you are finished. Do Not assume anything.
Write queries for each of the stated problems in the steps below that will return a result set of
data to satisfy the requirements. When finished, your resulting output file should show both the
query statement and result set for each query.
Deliverables
The deliverable for this lab will include:
Your script file with the seven queries and oneexplanation in it. Be sure your name, course
number, and lab number are in a comment area at the top of your file. An output file created
26. using SET ECHO ON showing both the SQL code and the results. Be sure that you include your
answer to question #3 as a comment in this file.
Both documents are to be zipped into a single file before submitting to the iLab Dropbox for
Week 7.
LABSTEPS
STEP 1:
Create a simple view named CUST_VIEW using the book_customer table that will display the
customer number, first and last name, and the state for every customer currently in the database.
Now insert the following data into the book_customer TABLE using an INSERT statement. (Do
not use the View for this insert.) CUSTOMERID - 1021, FIRSTNAME – EDWARD,
LASTNAME – BLAKE, STATE – TX. Now query your view and display the new record.
STEP 2:
Create a complex view named CUST_ORDER that will list the customer number, last name, and
state from the BOOK_CUSTOMER table, in addition to the order number and order date from
the BOOK_ORDER table. Insert the following data into this view (use the view for the insert
statement): CUSTOMERID - 1022, LASTNAME – smith, STATE – KS, ORDERID - 1021, and
ORDERDATE – 10-OCT-2004.
STEP 3:
In your own words, explain why the insert statement for the view you created in Step 2 did not
work.
STEP 4:
Create a sequence that can be used to assign a publisher ID number to a new publisher. Define
the sequence to start with seven, increment by two, and stop at 1000. Name the sequence
PUBNUM_SEQ.
STEP 5:
Insert two new publishers into the PUBLISHER table, one named Double Week with a contact
name of Jennifer Close at 800-959-6321, and the second one named Specific House with a
contact name of Freddie Farmore at 866-825-3200. Use your new sequence to create the PUBID
for each record. Now, query your PUBLISHER table to see your two new records.
27. STEP 6:
Using a single query, query the PUBNUM_SEQ to determine what both the current sequence
number is and the next sequence number will be.
STEP 7:
Create a unique index on the combined columns ORDERID and CUSTOMERID in the
BOOK_ORDER table. Give the index a name of BOOK_ORDER_IDX.
STEP 8:
Determine how many objects you currently own in your schema by querying the
USER_OBJECTS view in the Data Dictionary. Your result set should list the different object
types that you find and include a count by object type.