Sams Teach Yourself SQL in 24 Hours
- Table of Contents
- Copyright
- About the Authors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- Part I: A SQL Concepts Overview
- Hour 1. Welcome to the World of SQL
- Part II: Building Your Database
- Hour 2. Defining Data Structures
- Hour 3. Managing Database Objects
- Hour 4. The Normalization Process
- Hour 5. Manipulating Data
- Hour 6. Managing Database Transactions
- Part III: Getting Effective Results from Queries
- Hour 7. Introduction to the Database Query
- Hour 8. Using Operators to Categorize Data
- Hour 9. Summarizing Data Results from a Query
- Hour 10. Sorting and Grouping Data
- Hour 11. Restructuring the Appearance of Data
- Hour 12. Understanding Dates and Times
- Part IV: Building Sophisticated Database Queries
- Hour 13. Joining Tables in Queries
- Hour 14. Using Subqueries to Define Unknown Data
- Hour 15. Combining Multiple Queries into One
- Part V: SQL Performance Tuning
- Hour 16. Using Indexes to Improve Performance
- Hour 17. Improving Database Performance
- Part VI: Using SQL to Manage Users and Security
- Hour 18. Managing Database Users
- Hour 19. Managing Database Security
- Part VII: Summarized Data Structures
- Hour 20. Creating and Using Views and Synonyms
- Hour 21. Working with the System Catalog
- Part VIII: Applying SQL Fundamentals in Today's World
- Hour 22. Advanced SQL Topics
- Hour 23. Extending SQL to the Enterprise, the Internet, and the Intranet
- Hour 24. Extensions to Standard SQL
- Part IX: Appendixes
- Appendix A. Common SQL Commands
- Appendix B. Using MySQL for Exercises
- Appendix C. Answers to Quizzes and Exercises
- Appendix D. CREATE TABLE Statements for Book Examples
- Appendix E. INSERT Statements for Data in Book Examples
- Appendix F. Glossary
- Appendix G. Bonus Exercises
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
-
Would the use of a unique index on a small table be of any benefit?
-
What happens when the optimizer chooses not to use an index on a table when a query has been executed?
-
Should the most restrictive clause(s) be placed before the join condition(s) or after the join conditions in the WHERE clause?
-
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)
-
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'; -
SELECT LAST_NAME, FIRST_NAME FROM EMPLOYEE_TBL WHERE LAST_NAME LIKE '%ALL%;
-
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;
-
Exercises
Part VI: Using SQL to Manage Users and Security | Next Section

Account Sign In
View your cart