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 tthe quiz questions and exercises before continuing. Refer to Appendix C, "Answers to Quizzes and Exercises," for answers.

Quiz

1:Is the syntax correct for the following compound queries? If not, what would correct the syntax? Use the EMPLOYEE_TBL and the EMPLOYEE_PAY_TBL shown as follows:
EMPLOYEE_TBL  
EMP_IDVARCHAR2(9)NOT NULL,
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), 

CONSTRAINT EMP_PK PRIMARY KEY (EMP_ID)

EMPLOYEE_PAY_TBL   
EMP_IDVARCHAR2(9)NOT NULL,PRIMARY KEY
POSITIONVARCHAR2(15)NOT NULL, 
DATE_HIREDATE,  
PAY_RATENUMBER(4,2)NOT NULL, 
DATE_LAST_RAISEDATE,  
SALARYNUMBER(8,2),  
BONUSNUMBER(6,2),  

CONSTRAINT EMP_FK FOREIGN KEY (EMP_ID)
REFERENCES EMPLOYEE_TBL (EMP_ID)

  1. SELECT EMP_ID, LAST_NAME, FIRST_NAME
    FROM EMPLOYEE_TBL
    UNION
    SELECT EMP_ID, POSITION, DATE_HIRE
    FROM EMPLOYEE_PAY_TBL;
    										
  2. SELECT EMP_ID FROM EMPLOYEE_TBL
    UNION ALL
    SELECT EMP_ID FROM EMPLOYEE_PAY_TBL
    ORDER BY EMP_ID
    										
  3. SELECT EMP_ID FROM EMPLOYEE_PAY_TBL
    INTERSECT
    SELECT EMP_ID FROM EMPLOYEE_TBL
    ORDER BY 1;
    										
2:Match the correct operator to the following statements.
 STATEMENTOPERATOR
a.Show duplicatesUNION
b.Return only rows from the first query that match those in the second queryINTERSECT

UNION ALL

EXCEPT
c.Return no duplicates 
d.Return only rows from the first query not returned by the second 

Exercises

Use the CUSTOMER_TBL and the ORDERS_TBL as listed:

CUSTOMER_TBL   
CUST_INVARCHAR2(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  

1: Write a compound query to find the customers that have placed an order.
2:Write a compound query to find the customers that have not placed an order.
..................Content has been hidden....................

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