Vous êtes sur la page 1sur 2

CSIT 1810 SQL Lab 8 Table and Record Operations Due Thursday, Mar.

22nd -- 25 points
Launch SQL. Make sure you set echo on before you start recording script results. Insert your name and lab number into the session as you did in the previous lab. As you step through exercises for this part of the lab, keep in mind that if any queries require the use of a specific date format, then you might need to use an alter session command prior to running the select statement: alter session set nls_date_format=match-string to match the date format. For example, to match 11/13/2010 you would type alter session set nls_date_format=MM/DD/YYYY. The default date that is recognized depends on how the DBA has set up the system defaults. 1. a. Read page 253 to gain an understanding of the ALTER TABLE command as it is used to modify a columns attribute, but dont do the commands listed there. b. Read page 254 and add the P_SALECODE column to the PRODUCT table as specified in the ALTER command shown there. c. Try the UPDATE and SELECT commands on page 255 and the top of page 256. Try to gain an understanding of what you are doing and why the commands display the results that you are getting. Be sure to COMMIT these changes. d. Do the select and update commands on p. 256, then ROLLBACK to undo the updates. 2. Read section 7.5.6 starting on page 257, but dont do the commands listed there. 3. Create a new PART table and populate it with data by using a nested query (aka sub-query) within the create statement: create table Part as select P_Code as Part_Code, P_Descript as Part_Descript, P_Price as Part_Price, V_Code from Product; Verify that there is data in your new table with a SELECT statement. Select * from Part 4. Read section 7.5.7 but dont try the commands listed there. 5. Add a primary key to your new PART table using the following command: alter table Part add primary key (Part_Code); 5. Try the advanced queries section 7.6 from pages 259-269. Skip any commands that use tables that you have not yet created (i.e. EMPLOYEES, LINE, etc.). When you have finished, be sure you understand the purpose of the GROUP BY and HAVING clauses. Ask for clarification if there are steps that seem unclear.

6. Try creating views and joining tables together as specified in the commands in section 7.8 on pages 270-275. It is especially important that you gain an understanding of how the FROM and WHERE clauses are working together to result in the multiple table join. 7. Read the summary on page 276. Prepare questions to ask during lecture if there are concepts that still seem cloudy for you. 8. When you have finished this lab, save the script output file. Add the questions and answers to the exercises at the bottom of this page to your lab file. Note: You dont actually have to do these commands in SQL; just insert the statement that you would use to perform each task. Q1: Write a select statement that shows all products with a NULL vendor code. Q2: Write an update statement that changes the area code for all vendors that have the 615 code to 865. Q3: Write an SQL statement that creates a view of the product table joined with the vendor table that only displays the vendor name, vendor phone number and product description for products that each vendor supplies.