Your SlideShare is downloading. ×
Cis336 all i labs week 1 to week 7 devry university
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

Cis336 all i labs week 1 to week 7 devry university

1,535
views

Published on

Published in: Education, Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,535
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CIS 336 All iLabs Week 1 to Week 7 Devry UniversityClick 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 UniversityLABOVERVIEWScenario/SummaryThis lab will introduce you to the processes involved in defining one of the key components of adata model; the relationship diagram (RD). In this lab, you will draw a relationship diagram fortwo of the steps shown. Keep in mind when you are trying to decide which side of therelationship should be the "one" side and which should be the "many" that you must first decidewhich side has the primary key, or unique identifier. Once you have decided the primary key ofthe relationship, you have identified the "one" side of the relationship. Note that for an RD, theforeign key "many" side of the relationship points to the primary key "one" side. The "one" sideshould have the arrowhead point of the connecting line. This is different than anentity/relationship diagram (ERD) that we will draw next week, where the "many" side hascrows feet.This will familiarize you with how to set up MS Visio to draw database diagrams. Steps 1 - 3below use the Customer, Order, and Employee tables of a simplified Order Entry database. TheCustomer table records clients who have placed orders. The Order table contains the basic factsabout customer orders. The Employee table contains facts about employees who take orders. Theprimary keys of the tables are CustNo for Customer, EmpNo for Employee, and OrdNo forOrder.The following are the TABLE definitions for the first three tables showing the PRIMARY KEYconstraints.
  • 2. TABLE Customer has the following attributesCustNo 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 KEYTABLE Employee has the following attributesEmpNo NUMBER(5)EmpFirstName VARCHAR2(20)EmpLastName VARCHAR2(30)EmpPhone CHAR(15)EmpNo is the PRIMARY KEYTABLE Order has the following attributesOrdNo NUMBER(5)OrdDate DATECustNo NUMBER(5)EmpNo NUMBER(5)OrdNo is the PRIMARY KEYYour task for this lab is to create the required relationship diagram for steps 1 and 2 usingMicrosoft Visio. Step 3 will require you to analyze the scenario given and present your ownresolution to the question. Step 4 is an individual assignment that will introduce you to the groupproject and the process of identifying entities and attributes. When finished with the lab, youshould have a complete diagram using all 5 entities, a written explanation for #3, and two lists(entities and attributes) for Step 4.DeliverablesThe 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 listsof entities and attributes for the Initial Project Exercise (Step 4). You should copy and paste thediagram from MS Visio into a Word document and use this document for Steps 3 and 4.
  • 3. LABSTEPSSTEP 1: Drawing your first ER diagram TitleIdentify the foreign key columns in the table structures above and draw a relationship diagramdepicting the relationships between the tables. In the Order table , the CustNo column referencesthe 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 diagramExtend 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 willneed to identify the FOREIGN KEY(s) to complete this problem. When finished you shouldhave a total of 5 tables represented in your diagram for this problem. To copy and paste thediagram into Word, select Edit from the menu and then Copy Diagram. Open a Word documentand use CTRL-V to paste the diagram.TABLE Product has the following attributesProdNo CHAR(8)ProdName VARCHAR2(20)ProdNo is the PRIMARY KEYTABLE OrdLine has the following attributesOrdNo CHAR(8)ProdNo CHAR(8)Qty NUMBER(5)The combination of OrdNo and Prodno is the PRIMARY KEYSTEP 3: Should a NULL be allowed?From examination of the sample data and your current understanding of businesses in whichorders could be placed either in person, over the phone, or over the Internet, determine if itwould 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 whynot?
  • 4. OrdNo OrdDate CustNo EmpNoO1656777 02/11/2000 C8543321O7959898 02/19/2000 C8543321 E8544399STEP 4: Initial Project ExerciseAlthough the overall project itself will be done as a group, this first exercise is designed as anindividual 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 haveyou 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. Thisis 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 UniversityLab 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 anumber of things about the business, some of which will apply directly to the database you arebeing asked to model. There is a table which lists the entities (tables) that will be needed for thedatabase and related attributes (columns) for each entity. There is also a column that lists specificinformation about the entity that will be helpful in determining its relationship to other entitieswithin the model.Be sure to include the minimum and maximum occurrences of each relationship (cardinality) andto supply a name to the relationship that will work in both directions. If there is not a single wordthat will apply, then supply a separate name for each direction of the relationship.Narrative/Case StudyThe Clapham Specialty Store is a small, specialist grocery and delicatessen. A new owner, JohnBalfour, who would like to expand the store and improve its profits, has recently purchased thestore. The store sells general groceries, wines and liquors, and has a small deli counter. The storeis open from 5:00 a.m. to 12:00 midnight. Many of the customers are repeat customers whocome in to buy products they forgot from their regular grocery shopping expedition at thesupermarket.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 theaisle. 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 knowwhich 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 howbusy 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 everyemployee.All employees are paid weekly against an hourly rate which varies depending on their jobdescription.Each sale is identified by a Receipt No. and a timestamp (date and time) and consists of saleitems with a quantity and price recorded for each product.As a convenience for known customers, they offer a local delivery service. Deliveries are onlymade to customers who are registered at the store; walk-ins must record their name, address, andphone 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 apoint 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 thedelivery, how long the delivery takes, and the amount of the sale. There is concern at this pointthat 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 theinformation given to you by John and his staff. Through analysis of the nouns and verbs in thecase study above, you have accumulated the following entity, attribute, and relationshipinformation shown in the table below. The attribute list may not be complete. If you determinethat additional attributes are needed to better define an entity then you should add them.Entities Attributes and Relationships for Clapham Store:EntityAttributesRelationships
  • 6. EmployeeID Number, Last Name, First Name, Phone Number, Employee Type IDAn Employee can belong to any one of the three job categories, but can belong to one and onlyone of the three. Employees have names and other contact information.Employee TypeType ID, Description, Hourly Pay RateAn employee can be either a clerk, delivery person, or a supervisor.Register LogRegister Log Number, Register Number, Log In Time, Log Out Time, Employee IDSales are made using a register and can be tracked by the register log number. An employee mustlog into the register before he/she can use it and must log out when finished with a shift at thatregister. An employee may use more than one register during a period of work.RegisterRegister 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 thestore; one on the left and one on the right of the entrance.DeliveriesDelivery 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. Anemployee can make many deliveries but a sale is delivered by one and only one employee.LocationLocation ID, Aisle, Side, ShelfRelates to product and identifies one or more areas of the store where products are displayed.
  • 7. ProductProduct ID, Name, Package Size, Cost, Quantity on Hand (QOH), Last Purchased Date, ReorderMinimum Identifies the products the store sells. One or more products can be sold per sale. The quantityon hand allows John to determine his inventory levels. The reorder minimum can be used todetermine when the inventory level has reached a reorder point.SaleReceipt Number, Sales Amount, Sale Date- TimeA 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 onedelivery person.Sold ItemsReceipt Number, Product ID, Item Price, Quantity SoldSale Item is part of sale and records product sold per sale. Sale item must be able to associatemultiple products sold on a single sales receipt.CustomerCustomer 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 onecustomer. 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 Crows Foot notation. You will need todetermine the cardinality and optionality for each direction of the relationships. Some of theForeign Key relationships are identified in the graph above but not all. Be sure you identify andaccount for all Foreign Key relationships.Add a name (in both directions) to the relationships. Remember, if you can verbalize therelationship in both directions then you probably have a valid relationship.DeliverablesThe deliverable for this lab will be your completed ERD as a single MS Word document usingcopy/paste from the MS Visio application and named "lab2_solutions_yourname".LABSTEPSSTEP 1: Drawing entities and attributes
  • 9. Be sure to include all of the entities that have been defined. You need to include at least theprimary and foreign key attributes where applicable in your diagram.STEP 2: Indication of allrelationshipsBe sure that you link all entities based on PK to FK relationships. There may be a case whereyou need to identify a combination PK and if so make sure that all of the relationships involvedare defined. Be sure that you have set your Visio editor to show Crows Foot notation. Also, besure that you are defining the correct cardinality for the relationships.STEP 3: Naming of relationshipsDo not accept the default naming convention for your relationships in all cases. There may besome relationships where this is applicable, but in most cases you will want to explicitly namethe relationship. Be sure that you have provided a verb phrase for both directions in therelationship.This is the end of lab #2CIS 336 Week 3 iLab 3 Devry UniversityBeginning with this lab, and continuing through the remaining weeks you will be doing all ofyour work in Oracle itself. The editor interface to the Oracle server is SQL*Plus, and by nowyou have received your logon ID and password and should have at least made sure you canconnect. 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 anyproblems can be resolved.Before attempting Lab #3, you need to be sure you have read through the SQL*Plustutorial which can be found in Doc Sharing as well as under the SQL*Plus Tutorial tab in Week3. This tutorial describes the functionality of the editor and will take you through the process ofsetting up and using the SQL*Plus in the iLab environment so that it will best serve your needsfor the remainder of the labs required for this course.The lab for this week addresses taking a logical database design (data model) and nowtransforming 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 DataDiagram.xlsx, and Lab 3 Input Data.docx.Your job will be to take the meta data defined in the data dictionary spreadsheet document, andusing the relationship diagram as a guide define the table structures and constraints using bothCREATE TABLE and ALTER TABLE statements. Once this has been done, you will need towrite 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 anddata integrity constraints asked for. Lastly, you will write SELECT statements to query the tablesand verify the data was populated.Narrative/Case StudyFor this lab, you be working with command-line SQL to build a series of relational tables, usingSQL CREATE statements in a script file format for the Student Database and then populatethose 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 followingcode: 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 threedocuments 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 toreflect: • 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 constraintsCreate all PRIMARY KEY and NOT NULL constraints within the CREATE TABLE statementsat the column level (line level), unless the Primary Key is a composite Primary Key (yes, there isone). Composite Primary Key constraints must be created at the table level. Create all FOREIGNKEY and CHECK constraints at the table level using ALTER TABLE statements. All constraintsmust be added prior to populating the tables with data. Create all of the tables and all of theconstraints before populating any of the tables with data. Insert statements must be in the sameorder as the tables are created (follow the order in the sample data file). ALL character stringsmust be enclosed in single quotes. This includes alpha strings and alphanumeric (remember thatany formatting within a numeric strings makes it alphanumeric). If you are inserting a NULL, donot enclose the word NULL in single quotes, as this will insert the word NULL into the row. Toinsert a null you simply use the word NULL.DeliverablesThe 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 boththe SQL commands and results will show in the output. Be sure your name is on all documentsand that all documents have been included in a single Zip file for this week’s assignments. LABSTEPSSTEP 1: The DROP statementsThe following DROP TABLE statements must appear at the top of your script file. This willallow you to run and re-run your script file as often as you need to. The first time you run yourscript 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 thananything. 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 statementsNext, define the CREATE TABLE statements for the seven tables that you are to create basedupon the ERD and Data Dictionary that you have been given for this lab. Be sure to follow theguidelines given above on how and where to create the different types of constraints for eachtable.STEP 3: The INSERT statements for the dataThe third step is to create the insert statements to insert the sample data into the tables created inStep 2. You might find it helpful to take the Word document containing the sample data and saveit as a text file. After doing this, you could create the insert statements around the actual data thatis in that file. The process for doing this should have been covered in one of the lectures for thisunit. If it was not, then ask your instructor to discuss this process with the class.STEP 4: The SELECT statementsThe next step of the lab will be to create the select statements to verify the data was insertedcorrectly. You should have seven select statements; one for each table. The command isSELECT * FROM Table_Name; For example, to select all columns from the Student table, thecommand would be SELECT * FROM Student;Be sure to save all of the above statements in your script file.STEP 5: Testing and verifying your scriptNow we come to the point of verifying that your script file works by creating all of the tables andinserting all of the data. To verify this you will need to execute your saved script file and createan output file to capture the results being returned to the session by using the spool COMMANDoutlined in the tutorial "Using Oracle SQL*Plus." This output file will be one of the files youwill 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. Forinstructions on how to use the Dropbox, please click here.(See Syllabus/"Due Dates for Assignments & Exams" for due dates.)LABOVERVIEWScenario/SummaryLab #4 will introduce the various aspects of the SQL select statement and the methods ofretrieving 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 inthis class.The SELECT statement is the primary means of extracting data from database tables, and allowsyou to determine exactly which data you want to extract by means of different comparisonoperators used in the WHERE clause. This includes the use of specific "wild card" characterswhich allow you to search for character or number patterns within the data. You can alsoperform mathematical expressions within the SELECT statement to create derived output. TheORDER BY clause allows you to sort the output data in either ascending (the default) ordescending order. Lab #4 will explore all of these applications of the SELECT statement.General Lab Information and ConsiderationsEach query in the script file you will create must be numbered (use - -1 comments fornumbering) and listed in order. The SQL for the following exercises should be written usingNotepad 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 beexecuted without having to retype the code again each time. For this reason, it is important thatthere are no errors in the code inside the file. You can go back and forth between Notepad andOracle when creating your script file to check your queries and verify if they work or not, butyou do not want to create your final output file until after you have verified that everything inyour script is correct by running it, in its entirety at least once and viewing the output. Once thishas been done, you can create your final output file, with echo on to create the document you canturn in with your lab. Remember in using a spool session, you must type "SPOOL OFF" at theSQL> prompt after your script stops spooling to capture all of your data!Lab Dos and Don’tsDo 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 onequery.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 selectstatement to list them.SELECT * FROM TAB;If you want to know the name of the columns in a particular table, you can use the followingcommand to list them.DESCMaking a script file containing a series of describe statements for each table and then spoolingthe 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 ofdata to satisfy the requirements. When finished, your script file should have a total of 13 queriesand your resulting output file should show both the query and result set for each.DeliverablesThe 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 arein 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 forWeek 4.LABSTEPSSTEP 1:Using the BOOKS table, write a query that will list the categories for the books in inventory. Listeach 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 thetable. 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 ofmarkup for each book. The amount of markup is the retail price minus the cost. Use the columnheading “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, lastname, 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 placedprior to April 2, 2009.STEP 6:Using the BOOK_ORDER table, write a query that will list everything about the orders that havenot been shipped yet.STEP 7:Using the BOOK_CUSTOMER table, write a query using the AND and OR operators that willlist the customer information for those customers living in either Florida or New Jersey whohave 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 notcomputer 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 firstname ends with an “A”. Put the results in descending order of last name, and then ascendingorder 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 theorders that were placed between April 1, 2009 and April 4, 2009. Only show the orders for April2nd and 3rd in your result set.STEP 11:Using the BOOK_ORDER table, write a query that will list the orders that were placed betweenApril 2, 2009 and April 4, 2009 including those placed on the 2nd and 4th. Use a differentapproach (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 publisheddate for all books that were published by publisher 4 or after January 1, 2001. Order the results inascending order by publisher ID and give the publish date and publisher ID columns meaningfultitles.STEP 13:Many organizations use percentage of markup (e.g., profit margin) when analyzing financialdata. To determine the percentage of markup for a particular item, simply subtract the cost forthe item from the retail price to obtain the dollar amount of profit, and then divide the profit bythe cost of the item. The resulting solution is then multiplied by 100 to determine the percent ofmarkup. 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 #4CIS 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. Forinstructions on how to use the Dropbox, please click here.(See Syllabus/"Due Dates for Assignments & Exams" for due dates.)LABOVERVIEWScenario/SummaryLab 5 deals with writing queries using multiple tables as covered in the reading and lecturematerial this week. In some cases, you will be given the option to write a query using either theTRADITIONAL method of joining tables or using the JOIN key word. In some cases, you willbe asked to use a specific approach. Using the incorrect process when the process is specifiedwill result in points being taken off for that problem.The SELECT statement is the primary means of extracting data from database tables, and allowsyou to determine exactly which data you want to extract by means of different comparisonoperators used in the WHERE clause. This includes the use of specific "wild card" characterswhich allow you to search for character or number patterns within the data. You can alsoperform mathematical expressions within the SELECT statement to create derived output. TheORDER BY clause allows you to sort the output data in either ascending (the default) ordescending order. Lab #5 will explore all of these applications of the SELECT statement.General Lab Information and ConsiderationsThis lab will utilize a set of tables found in the script file (LeeBooks.sql) found in the DocSharing area of the website. If you have not yet downloaded this file from Doc Sharing then doso 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 inSQL*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 beexecuted without having to retype the code again each time. For this reason, it is important thatthere are no errors in the code inside the file. You can go back and forth between Notepad andOracle when creating your script file to check your queries and verify if they work or not, butyou do not want to create your final output file until after you have verified that everything inyour script is correct by running it, in its entirety at least once and viewing the output. Once thishas been done, you can create your final output file, with echo on to create the document you canturn 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 Dos and Don’tsDo 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 onequery.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 selectstatement to list them.SELECT * FROM TAB;If you want to know the name of the columns in a particular table, you can use the followingcommand to list them.DESCMaking a script file containing a series of describe statements for each table and then spoolingthe 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 ofdata to satisfy the requirements. When finished, your script file should have a total of 13 queriesand your resulting output file should show both the query and result set for each.
  • 19. DeliverablesSubmit for grading:Your script file with the 13 queries in it. Be sure your name, course number, and lab number arein a comment area at the top of your file. Submitting ONLY your spooled output will result in a10-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 forWeek 5.LABSTEPSSTEP 1:Using the BOOKS and PUBLISHER tables, create a query using the traditional join method thatwill return a list containing the book title, publisher contact person, and publisher phone numberfor 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, andseconds 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 theNATURAL JOIN method that will return a list containing the customer first name and last nameand the order number for all orders that have been shipped. Give the customer name column analias of "Customer Name" and order the output by the customer number in the BOOK_ORDERtable 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 theorder date to display as Month DD, YYYY and give the column an alias of "Date Ordered". Besure the month begins with a capital letter.STEP 5:Using the BOOK_ORDER table, create a query using the correct function to return the ordernumber, the date ordered, the date shipped, and a column representing the number of monthsbetween 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 "MonthsBetween".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 listthe title of each book and author name(s). Give the title column an alias of "Book Title". Sort theresults 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 allbooks with a title starting with the letter ‘H’. Use the correct conversion function to format thecost and retail columns to show dollars and cents with a dollar sign (e.g., a price of $25 woulddisplay $25.00 in the result set).STEP 8:Using the BOOK_ORDER, ORDER_ITEMS, and BOOKS tables, create a query using anOUTER JOIN operation that will list the book title, order date, and order number for all books inthe BOOKS table. Order your output in descending order by ORDER_ITEMS.BOOKID. Thereare 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 thecustomer first and last name, book title, and order date (formatted as MM/DD/YYYY with analias of “Order Date”) for all the customers who have purchased books published by PRINTINGIS US.STEP 10:Using the BOOKS and ORDER_ITEMS table, write a query using the correct Relational SetOperator 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, createa query using traditional join conditions based on comparisons between primary and foreign keysthat will list the customer number, first and last name, and book title. Limit your listing to onlythose books in the ‘FITNESS’ category.STEP 12:
  • 21. Using the BOOKS, ORDER_ITEMS, and BOOK_ORDER tables, create a query that will list thetitle, 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 theorder 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 pricecolumn using the correct function to show dollars and cents with a dollar sign ( $ ) and a columnalias of “Retail”.This is the end of lab #5CIS 336 Week 6 iLab 6 Devry UniversityLab 6 of 7:Oracle Single Row and Group Functions (28 points) Lab #6 will introduce the various aspects of theSingle-Row and Group Functions available in the Oracle Database. Most functions can be used in eitherthe SELECT statement or the WHERE clause, but more commonly are used in the SELECT. Chapters 5 and6 cover most all of the normal processing you use in these functions. In some cases, you will be asked toused more than one function within a single SELECT statement. General Lab Information andConsiderations This lab will utilize the same set of tables found in the script file (LeeBooks.SQL) thatwere used for Labs 4 and 5. Each query in the script file you will create must be numbered (use --1comments for numbering) and in order. The SQL for the following exercises should be written usingnotepad and run in SQL*Plus. Read each problem carefully and follow the directions as stated. A CleanScript File: A script file is meant to be like a program. The file can be run every time the code needs to beexecuted without having to retype the code again each time. For this reason, it is important that thereare no errors in the code inside the file. You can go back and forth between notepad and Oracle whencreating your script file to check your queries and verify if they work or not. However, you do not wantto create your final output file until after you have verified that everything in your script is correct byrunning it, in its entirety at least once and viewing the output. Once this has been done, you can createyour final output file, with echo to create the document, you can turn in with your lab. Remember inusing a spool session, you must type "SPOOL OFF" at the SQL> prompt after your script stops spooling tocapture all of your data! Lab Dos and Don’ts * Do Not include the LEEBOOKS.SQL as part of your labscript. o Do use Notepad to write your query script file. * Do Not write your queries in Word. o Do testeach query before moving on to the next. * Do Not include extra queries for a problem unless theproblem explicitly asks for more than one query. o Do test your queries before creating your final outputfile. * Do Not turn in a script file that has queries with errors. o Do number each query using - -1comment notation. * Do Not start your query on the same line as the comment. o Do remember tocheck your final output and script file for accuracy. * Do Not turn in your lab without first checking youroutput file to verify that it is correct. Things to keep in mind: If you are not sure of the table names inyour 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 listthem. DESC Making a script file containing a series of describe statements for each table and thenspooling the output will give you a listing of all the tables with column names. Be sure to review andverify your final output when you are finished. Do Not assume anything. Write queries for each of thestated 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 shouldshow both the query and result set for each. Deliverables Submit for grading: 1. Your script file with the13 queries in it. Be sure your name, course number, and lab number are in a comment area at the top ofyour 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 6Week 6. L A B S T E P SSTEP 1: Back to top Using the BOOK_CUSTOMER table and the NVL function, create a query that willreturn 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 REFERREDBY. 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 listof 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 thecategory name, the total retail of all books per category with a column alias of "Total Retail", and theaverage retail of all the books per category with an alias of "Average Retail" for all categories with a totalretail greater than $40.00. Format the total retail and average retail columns using the correct functionto 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 operationyou wish that will list the book title and number of authors for all books that have been written by morethan one author. Give the title column an alias of "Book Title" and the column showing the number ofauthors an alias of "Number of Authors".STEP 5: Back to top Using the BOOK_AUTHOR and AUTHOR tables for the upper most query, create asub query that will return the BOOKID, and the first and last name of the author(s) who have written thebook(s) that have been purchased the most. To successfully accomplish this, you will need to first findout the maximum total number of copies (based on quantity) sold of a book (based on bookid) in theORDER_ITEMS table. This will be done in the bottom most query. The return from this query will be usedto compare against the BOOKID in the ORDER_ITEMS table that occurs an equal number of times in themiddle query. The return of this query will then be used to compare to a BOOKID related to an Author inthe tables of the top most query. (HINT: Be careful, you will need both GROUP BY and HAVING clausesfor your solution.)
  • 23. STEP 6: Back to top Using the correct tables, create a sub query using either join operation you wish thatwill list the customer number, first and last name concatenated together, and city for all customers whohave placed an order for the most expensive book (based on retail price). Give the combined customernames column and alias of "Customer Name".STEP 7: Back to top Using the ORDER_ITEMS table, create a query using the correct functions to returnthe item#, the total quantity of items ordered with an alias of "Total", the average quantity per orderwith an alias of "Average" (since averages are often in decimals, only show two decimal places), theminimum quantity ordered with an alias of "Minimum", and the maximum quantity ordered with analias 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 displaythe 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 indescending order. The publisher names used should be the same as those in the PUBLISHER table. DONOT 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 theone below for each record in the table. Be sure to use the correct functions in the SELECT statement, sothat your output looks like the example below. The contact person for Printing Is Us Publishing isTommie Seymour. Be sure to use the correct function to display the publisher name and publishercontact 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 alisting of all customers who have purchased more than two books. List the customer’s last name, thecustomer’s city and state, and the number of books they have purchased. Give the number purchasedcolumn and alias of "Number Purchased".STEP 11: Back to top Using only the BOOK table for the upper most statement, create a sub query thatwill 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 verifyyour update, provide a select statement on the BOOKS table before your update statement, and then asecond select on the BOOKS table after the update. Once you have verified the results, you can issue aROLLBACK 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 ofthose customers who were referred by the same individual who referred Jorge Perez. Do not displayJorge Perez’s name in the returned results (Hint: you should only have two customers displayed and theexclusion 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 thecategory name, total number books per category with a column alias of "Category Total", and the totalcost of all the books per category with an alias of "Cost". Format the cost column using the correctfunction 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 UniversityLABOVERVIEWScenario/SummaryThere is a lot more to a database than just tables and the data in them. A very important part ofdatabase security has to do with using and understanding Database Views. Being able to enhancethe efficiency of the database tables by using additional indexes is also a very important aspect ofdatabase development. Finally, being able to create and use Database Sequences to automatesome 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 ConsiderationsThis lab will utilize the same set of tables found in the script file (LeeBooks.SQL) that were usedfor Labs 4 through 6.Each query in the script file you will create, must be numbered (use either –1 or REM 1comments for numbering) and in order. The SQL for the following exercises should be writtenusing notepad and run in SQL*Plus. Read each problem carefully and follow the directions asstated.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 beexecuted without having to retype the code again each time. For this reason, it is important thatthere are no errors in the code inside the file. You can go back and forth between notepad andOracle 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 thateverything in your script is correct by running it in its entirety at least once and viewing theoutput. Once this has been done, you can create your final output file, with echo on to create thedocument, 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 yourdata!Lab Dos and DontsDo Not include the LEEBOOKS.SQL as part of your lab script. Do use Notepad to write yourquery 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 onequery.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 selectstatement to list them.SELECT * FROM TAB;If you want to know the name of the columns in a particular table, you can use the followingcommand to list them.DESCMaking a script file containing a series of describe statements for each table and then spoolingthe 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 ofdata to satisfy the requirements. When finished, your resulting output file should show both thequery statement and result set for each query.DeliverablesThe deliverable for this lab will include:Your script file with the seven queries and oneexplanation in it. Be sure your name, coursenumber, 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 youranswer 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 forWeek 7.LABSTEPSSTEP 1:Create a simple view named CUST_VIEW using the book_customer table that will display thecustomer 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. (Donot 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, andstate from the BOOK_CUSTOMER table, in addition to the order number and order date fromthe BOOK_ORDER table. Insert the following data into this view (use the view for the insertstatement): CUSTOMERID - 1022, LASTNAME – smith, STATE – KS, ORDERID - 1021, andORDERDATE – 10-OCT-2004.STEP 3:In your own words, explain why the insert statement for the view you created in Step 2 did notwork.STEP 4:Create a sequence that can be used to assign a publisher ID number to a new publisher. Definethe sequence to start with seven, increment by two, and stop at 1000. Name the sequencePUBNUM_SEQ.STEP 5:Insert two new publishers into the PUBLISHER table, one named Double Week with a contactname of Jennifer Close at 800-959-6321, and the second one named Specific House with acontact name of Freddie Farmore at 866-825-3200. Use your new sequence to create the PUBIDfor 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 sequencenumber is and the next sequence number will be.STEP 7:Create a unique index on the combined columns ORDERID and CUSTOMERID in theBOOK_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 theUSER_OBJECTS view in the Data Dictionary. Your result set should list the different objecttypes that you find and include a count by object type.