Workshop

The following workshop is composed of a series of quiz questions and practical exercises. The quiz questions are designed to test your overall understanding of the current material. The practical exercises are intended to afford you the opportunity to apply the concepts discussed during the current hour, as well as build upon the knowledge acquired in previous hours of study. Please take time to complete the quiz questions and exercises before continuing. Refer to Appendix C, "Answers to Quizzes and Exercises," for answers.

Quiz

1:What is the function of a subquery when used with a SELECT statement?
2:Can you update more than one column when using the UPDATE statement in conjunction with a subquery?
3:Are the following syntaxes correct? If not, what is the correct syntax?
  1. SELECT CUST_ID, CUST_NAME
            FROM CUSTOMER_TBL
            WHERE CUST_ID =
                           (SELECT CUST_ID
                                   FROM ORDERS_TBL
                                   WHERE ORD_NUM = '16C17'),
    										
  2. SELECT EMP_ID, SALARY
           FROM EMPLOYEE_PAY_TBL
           WHERE SALARY BETWEEN '20000'
                        AND (SELECT SALARY
                             FROM EMPLOYEE_ID
                             WHERE SALARY = '40000'),
    										
  3. UPDATE PRODUCTS_TBL
       SET COST = 1.15
       WHERE CUST_ID =
                      (SELECT CUST_ID
                       FROM ORDERS_TBL
                       WHERE ORD_NUM = '32A132'),
    										
4:What would happen if the following statement were run?
DELETE FROM EMPLOYEE_TBL
WHERE EMP_ID IN
              (SELECT EMP_ID
              FROM EMPLOYEE_PAY_TBL);

Exercises

Use the following tables to complete the exercises:

EMPLOYEE_TBL   
EMP_IDVARCHAR2(9)NOT NULLPRIMARY KEY
LAST_NAMEVARCHAR2(15)NOT NULL 
FIRST_NAMEVARCHAR2(15)NOT NULL 
MIDDLE_NAMEVARCHAR2(15)  
ADDRESSVARCHAR2(30)NOT NULL 
CITYVARCHAR2(15)NOT NULL 
STATECHAR(2)NOT NULL 
ZIPNUMBER(5)NOT NULL 
PHONECHAR(10)  
PAGERCHAR(10)  

EMPLOYEE_TBL   
EMP_IDVARCHAR2(9)NOT NULLPRIMARY KEY
POSITIONVARCHAR2(15)NOT NULL 
DATE_HIREDATE  
PAY_RATENYMBER(4,2)NOT NULL 
DATE_LAST_RAISEDATE  
CONSTRAINT EMP_FK FOREIGN KEY (EMP_ID_REFERENCES EMPLOYEE_TBL (EMP_ID)

CUSTOMER_TBL   
CUST_IDVARCHAR2(10)NOT NULLPRIMARY KEY
CUST_NAMEVARCHAR2(30)NOT NULL 
CUST_ADDRESSVARCHAR2(20)NOT NULL 
CUST_CITYVARCHAR2(15)NOT NULL 
CUST_STATECHAR(2)NOT NULL 
CUST_ZIPNUMBER(5)NOT NULL 
CUST_PHONENUMBER(10)  
CUST_FAXNUMBER(10)  

ORDERS_TBL   
ORD_NUMVARCHAR2(10)NOT NULLPRIMARY KEY
CUST_IDVARCHAR2(10)NOT NULL 
PROD_IDVARCHAR2(10)NOT NULL 
QTYNUMBER(6)NOT NULL 
ORD_DATEDATE  

PRODUCTS_TBL   
PROD_IDVARCHAR2(10)NOT NULLPRIMARY KEY
PROD_DESCVARCHAR2(40)NOT NULL 
COSTNUMBER(6,2)NOT NULL 

1:Using a subquery, write an SQL statement to update the CUSTOMER_TBL table, changing the customer name to DAVIDS MARKET, who has an order with order number 23E934.
2:Using a subquery, write a query that returns all the names of all employees who have a pay rate greater than JOHN DOE, whose employee identification number is 343559876.
3:Using a subquery, write a query that lists all products that cost more than the average cost of all products.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset