Workshop

Team-Fly    

 
Sams Teach Yourself SQL in 24 Hours, Third Edition
By Ronald R. Plew, Ryan K. Stephens
Table of Contents
Hour  17.  Improving Database Performance


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:

Would the use of a unique index on a small table be of any benefit?

2:

What happens when the optimizer chooses not to use an index on a table when a query has been executed?

3:

Should the most restrictive clause(s) be placed before the join condition(s) or after the join conditions in the WHERE clause?

Exercises

Q1:

Rewrite the following SQL statements to improve their performance. Use the EMPLOYEE_TBL and the EMPLOYEE_PAY_TBL as described here:

EMPLOYEE_TBL

EMP_ID

VARCHAR(9)

NOT NULL Primary key,

LAST_NAME

VARCHAR(15)

NOT NULL,

FIRST_NAME

VARCHAR(15)

NOT NULL,

MIDDLE_NAME

VARCHAR(15),

 

ADDRESS

VARCHAR(30)

NOT NULL,

CITY

VARCHAR(15)

NOT NULL,

STATE

varCHAR(2)

NOT NULL,

ZIP

INTEGER(5)

NOT NULL,

PHONE

VARCHAR(10),

 

PAGER

VARCHAR(10),

 
 CONSTRAINT EMP_PK PRIMARY KEY (EMP_ID) 

EMPLOYEE_PAY_TBL

EMP_ID

VARCHAR(9)

NOT NULL primary key,

POSITION

VARCHAR(15)

NOT NULL,

DATE_HIRE

DATETIME,

 

PAY_RATE

DECIMAL(4,2)

NOT NULL,

DATE_LAST_RAISE

DATETIME,

 

SALARY

DECIMAL(8,2),

 

BONUS

DECIMAL(8,2),

 
 CONSTRAINT EMP_FK FOREIGN KEY (EMP_ID)    REFERENCES EMPLOYEE_TBL (EMP_ID) 
  1.  SELECT EMP_ID, LAST_NAME, FIRST_NAME,            PHONE    FROM EMPLOYEE_TBL    WHERE SUBSTRING(PHONE, 1, 3) = '317' OR          SUBSTRING(PHONE, 1, 3) = '812' OR          SUBSTRING(PHONE, 1, 3) = '765'; 
  2.  SELECT LAST_NAME, FIRST_NAME     FROM EMPLOYEE_TBL    WHERE LAST_NAME LIKE '%ALL%; 
  3.  SELECT E.EMP_ID, E.LAST_NAME, E.FIRST_NAME,            EP.SALARY    FROM EMPLOYEE_TBL E,    EMPLOYEE_PAY_TBL EP    WHERE LAST_NAME LIKE 'S%'    AND E.EMP_ID = EP.EMP_ID; 

Team-Fly    
Top
 


Sams Teach Yourself SQL in 24 Hours
Sams Teach Yourself SQL in 24 Hours (5th Edition) (Sams Teach Yourself -- Hours)
ISBN: 0672335417
EAN: 2147483647
Year: 2002
Pages: 275

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net