Book description
The Classic SQL Tutorial: Fully Updated for Today’s Standards and Today’s Top Databases
For twenty years, van der Lans’ Introduction to SQL has been the definitive SQL tutorial for database professionals everywhere, regardless of experience or platform. Now van der Lans has systematically updated this classic guide to reflect the latest SQL standards and the newest versions of today’s leading RDBMSs: Oracle, Microsoft SQL Server, DB2, and MySQL.
Using case study examples and hands-on exercises, van der Lans illuminates every key SQL concept, technique, and statement. Drawing on decades of experience as an SQL standards team member and enterprise consultant, he reveals exactly why SQL works as it does–and how to get the most out of it. You’ll gain powerful insight into everything from basic queries to stored procedures, transactions to data security. Whether you’re a programmer or DBA, a student or veteran, this book will take you from “apprentice” to true SQL master.
Writing queries and updating data: all you need to know about SELECT
Working with joins, functions, and subqueries
Creating database objects: tables, indexes, views, and more
Specifying keys and other integrity constraints
Using indexes to improve efficiency
Enforcing security via passwords and privileges
Building stored procedures and triggers
Developing with embedded SQL and ODBC
Working with transactions, including rollbacks, savepoints, isolation levels, and more
Optimizing performance by reformulating SQL statements
Using object-relational features: subtables, references, sets, and user-defined data types
Reference section: SQL statement definitions and SQL function lists
Table of contents
- Copyright
- About the Author
- Preface
-
I. Introduction
-
1. Introduction to SQL
- 1.1. Introduction
- 1.2. Database, Database Server, and Database Language
- 1.3. The Relational Model
- 1.4. What Is SQL?
- 1.5. Several Categories of SQL Applications
- 1.6. The History of SQL
- 1.7. From Monolithic via Client/Server to the Internet
- 1.8. Transaction Databases and Data Warehouses
- 1.9. Standardization of SQL
- 1.10. The Market of SQL Database Servers
- 1.11. Which SQL Dialect?
- 1.12. The Structure of the Book
- 2. The Tennis Club Sample Database
- 3. Installing the Software
-
4. SQL in a Nutshell
- 4.1. Introduction
- 4.2. Logging On to the MySQL Database Server
- 4.3. Creating New SQL Users
- 4.4. Creating Databases
- 4.5. Selecting the Current Database
- 4.6. Creating Tables
- 4.7. The NULL Value
- 4.8. Populating Tables with Data
- 4.9. Querying Tables
- 4.10. Updating and Deleting Rows
- 4.11. Optimizing Query Processing with Indexes
- 4.12. Views
- 4.13. Users and Data Security
- 4.14. Deleting Database Objects
- 4.15. System Parameters
- 4.16. Grouping of SQL Statements
- 4.17. The Catalog Tables
- 4.18. Definitions of SQL Statements
-
1. Introduction to SQL
-
II. Querying and Updating Data
-
5. SELECT Statement: Common Elements
- 5.1. Introduction
- 5.2. Literals and Their Data Types
- 5.3. Expressions
- 5.4. Assigning Names to Result Columns
- 5.5. The Column Specification
- 5.6. The User Variable and the SET Statement
- 5.7. The System Variable
- 5.8. The Case Expression
- 5.9. The Scalar Expression Between Brackets
- 5.10. The Scalar Function
- 5.11. Casting of Expressions
- 5.12. The NULL Value as an Expression
- 5.13. The Compound Scalar Expression
- 5.14. The Aggregation Function and the Scalar Subquery
- 5.15. The Row Expression
- 5.16. The Table Expression
- 5.17. Answers
- 6. SELECT Statements, Table Expressions, and Subqueries
-
7. SELECT Statement: The FROM Clause
- 7.1. Introduction
- 7.2. Table Specifications in the FROM Clause
- 7.3. Again, the Column Specification
- 7.4. Multiple Table Specifications in the FROM Clause
- 7.5. Pseudonyms for Table Names
- 7.6. Various Examples of Joins
- 7.7. Mandatory Use of Pseudonyms
- 7.8. Explicit Joins in the FROM Clause
- 7.9. Joins with USING
- 7.10. Outer Joins
- 7.11. Additional Conditions in the Join Condition
- 7.12. The Cross Join
- 7.13. The Union Join and the Natural Join
- 7.14. Equi Joins and Theta Joins
- 7.15. The FROM Clause with Table Expressions
- 7.16. Answers
-
8. SELECT Statement: The WHERE Clause
- 8.1. Introduction
- 8.2. Conditions Using Comparison Operators
- 8.3. Comparison Operators with Subqueries
- 8.4. Comparison Operators with Correlated Subqueries
- 8.5. Conditions Coupled with AND, OR, and NOT
- 8.6. The IN Operator with Expression List
- 8.7. The IN Operator with Subquery
- 8.8. The BETWEEN Operator
- 8.9. The LIKE Operator
- 8.10. The IS NULL Operator
- 8.11. The EXISTS Operator
- 8.12. The ALL and ANY Operators
- 8.13. Scope of Columns in Subqueries
- 8.14. More Examples with Correlated Subqueries
- 8.15. Conditions with Negation
- 8.16. Future Conditions
- 8.17. Answers
-
9. SELECT Statement: SELECT Clause and Aggregation Functions
- 9.1. Introduction
- 9.2. Selecting All Columns (*)
- 9.3. Expressions in the SELECT Clause
- 9.4. Removing Duplicate Rows with DISTINCT
- 9.5. When Are Two Rows Equal?
- 9.6. An Introduction to Aggregation Functions
- 9.7. The COUNT Function
- 9.8. The MAX and MIN Functions
- 9.9. The SUM and AVG Functions
- 9.10. The VARIANCE and STDDEV Functions
- 9.11. Answers
-
10. SELECT Statement: The GROUP BY Clause
- 10.1. Introduction
- 10.2. Grouping on One Column
- 10.3. Grouping on Two or More Columns
- 10.4. Grouping on Expressions
- 10.5. Grouping of NULL Values
- 10.6. General Rules for the GROUP BY Clause
- 10.7. Complex Examples with GROUP BY
- 10.8. Grouping with WITH ROLLUP
- 10.9. Grouping with WITH CUBE
- 10.10. Grouping Sets
- 10.11. Grouping with ROLLUP and CUBE
- 10.12. Combining Grouping Sets
- 10.13. Answers
- 11. SELECT Statement: The HAVING Clause
- 12. SELECT Statement: The ORDER BY Clause
- 13. Combining Table Expressions
- 14. Updating Tables
-
5. SELECT Statement: Common Elements
-
III. Creating Database Objects
- 15. Creating Tables
- 16. Specifying Integrity Constraints
-
17. Character Sets and Collating Sequences
- 17.1. Introduction
- 17.2. Available Character Sets and Collating Sequences
- 17.3. Assigning Character Sets to Columns
- 17.4. Assigning Collating Sequences to Columns
- 17.5. Expressions with Character Sets and Collating Sequences
- 17.6. Sorting and Grouping with Collating Sequences
- 17.7. The Coercibility of Expressions
- 17.8. Related System Variables
- 17.9. Answers
- 18. Changing and Dropping Tables
-
19. Designing Tables
- 19.1. Introduction
- 19.2. Which Tables and Columns?
- 19.3. Adding Redundant Data
-
19.4. Choosing a Data Type for a Column
- Guideline 6: Use the Same Data Types for Columns That Will Be Compared with One Another
- Guideline 7: Assign a Column a Numeric Data Type Only if It Will Be Used in Calculations
- Guideline 8: Do Not Skimp on the Length of Columns
- Guideline 9: Do Not Use the Data Type VARCHAR for All Alphanumeric Columns
- 19.5. When Should You Use NOT NULL?
- 19.6. Answers
-
20. Using Indexes
- 20.1. Introduction
- 20.2. Rows, Tables, and Files
- 20.3. How Does an Index Work?
- 20.4. Processing a SELECT Statement: The Steps
- 20.5. Creating Indexes
- 20.6. Dropping Indexes
- 20.7. Indexes and Primary Keys
- 20.8. The Big PLAYERS_XXL Table
- 20.9. Choosing Columns for Indexes
- 20.10. Special Index Forms
- 20.11. Indexes and the Catalog
- 20.12. Answers
-
21. Views
- 21.1. Introduction
- 21.2. Creating Views
- 21.3. The Column Names of Views
- 21.4. Updating Views: WITH CHECK OPTION
- 21.5. Deleting Views
- 21.6. Views and the Catalog
- 21.7. Restrictions on Querying Views
- 21.8. Restrictions on Updating Views
- 21.9. Processing View Statements
- 21.10. Application Areas for Views
- 21.11. Answers
- 22. Creating Databases
-
23. Users and Data Security
- 23.1. Introduction
- 23.2. Adding and Removing Users
- 23.3. Granting Table and Column Privileges
- 23.4. Granting Database Privileges
- 23.5. Granting User Privileges
- 23.6. Passing on Privileges: WITH GRANT OPTION
- 23.7. Working with Roles
- 23.8. Recording Privileges in the Catalog
- 23.9. Revoking Privileges
- 23.10. Security of and Through Views
- 23.11. Answers
- 24. Creating Sequences
- 25. Creating Schemas
-
IV. Programming with SQL
-
26. Introduction to Embedded SQL
- 26.1. Introduction
- 26.2. The Pseudo Programming Language
- 26.3. DDL and DCL Statements and Embedded SQL
- 26.4. Processing Programs
- 26.5. Using Host Variables in SQL Statements
- 26.6. The SQLCODE Host Variable
- 26.7. Executable Versus Nonexecutable SQL Statements
- 26.8. The WHENEVER Statement
- 26.9. Logging On to SQL
- 26.10. SELECT Statements Returning One Row
- 26.11. NULL Values and the NULL Indicator
- 26.12. Cursors for Querying Multiple Rows
- 26.13. The Direction for Browsing Through a Cursor
- 26.14. Processing Cursors
- 26.15. The FOR Clause
- 26.16. Deleting Rows via Cursors
- 26.17. Dynamic SQL
- 26.18. Example of a C Program
-
27. Transactions and Multi-User Usage
- 27.1. Introduction
- 27.2. What Is a Transaction?
- 27.3. Starting Transactions
- 27.4. Embedded SQL and Transactions
- 27.5. Savepoints
- 27.6. Problems with Multi-User Usage
- 27.7. Locking
- 27.8. Deadlocks
- 27.9. The Granularity of Locked Data
- 27.10. The LOCK TABLE Statement
- 27.11. The Isolation Level
- 27.12. Answers
-
28. Introduction to ODBC
- 28.1. Introduction
- 28.2. The History of ODBC
- 28.3. How Does ODBC Work?
- 28.4. A Simple Example of ODBC
- 28.5. Return Codes
- 28.6. Retrieving Data About SQL
- 28.7. DDL Statements and ODBC
- 28.8. DML Statements and ODBC
- 28.9. Using Host Variables in SQL Statements
- 28.10. Settings for a Statement Handle
- 28.11. SELECT Statements
- 28.12. Asynchronous Processing of SQL Statements
- 28.13. The FOR Clause
- 28.14. Accessing Catalog Tables with ODBC
- 28.15. Levels and Support
- 28.16. The Competitors of ODBC
-
29. Optimization of Statements
- 29.1. Introduction
- 29.2. Avoid the OR Operator
- 29.3. Avoid Unnecessary Use of the UNION Operator
- 29.4. Avoid the NOT Operator
- 29.5. Isolate Columns in Conditions
- 29.6. Use the BETWEEN Operator
- 29.7. Avoid Particular Forms of the LIKE Operator
- 29.8. Add Redundant Conditions to Joins
- 29.9. Avoid the HAVING Clause
- 29.10. Make the SELECT Clause as Small as Possible
- 29.11. Avoid DISTINCT
- 29.12. Use the ALL Option with Set Operators
- 29.13. Prefer Outer Joins to UNION Operators
- 29.14. Avoid Data Type Conversions
- 29.15. The Largest Table Last
- 29.16. Avoid the ANY and ALL Operators
- 29.17. The Future of the Optimizer
- 29.18. Answers
-
26. Introduction to Embedded SQL
-
V. Procedural Database Objects
-
30. Stored Procedures
- 30.1. Introduction
- 30.2. An Example of a Stored Procedure
- 30.3. The Parameters of a Stored Procedure
- 30.4. The Body of a Stored Procedure
- 30.5. Local Variables
- 30.6. The SET Statement
- 30.7. Flow-Control Statements
- 30.8. Calling Stored Procedures
- 30.9. Stored Procedures with SELECT INTO
- 30.10. Error Messages, Handlers, and Conditions
- 30.11. Stored Procedures with a Cursor
- 30.12. Stored Procedures and Transactions
- 30.13. Stored Procedures and the Catalog
- 30.14. Removing Stored Procedures
- 30.15. Compiling and Recompiling
- 30.16. Security with Stored Procedures
- 30.17. Advantages of Stored Procedures
- 31. Stored Functions
- 32. Triggers
-
30. Stored Procedures
- VI. Object Relational Concepts
- A. Syntax of SQL
-
B. Scalar Functions
- ABS(par1)
- ACOS(par1)
- ADDDATE(par1, par2)
- ADDTIME(par1, par2)
- ASCII(par1)
- ASIN(par1)
- ATAN(par1)
- ATAN2(par1, par2)
- ATANH(par1)
- BIN(par1)
- BIT_COUNT(par1)
- BIT_LENGTH(par1)
- CEILING(par1)
- CHAR(par1)
- CHARACTER_LENGTH(par1)
- CHARSET(par1)
- CHAR_LENGTH(par1)
- CHR(par1)
- COALESCE(par1, par2, par3, ...)
- COERCIBILITY(par1)
- COLLATION (par1)
- CONCAT(par1, part2)
- CONNECTION_ID()
- CONV(par1, part2, par3)
- CONVERT(par1, par2)
- CONVERT_TZ(par1, part2, par3)
- COS(par1)
- COT(par1)
- CURDATE()
- CURRENT_DATE()
- CURRENT_TIME()
- CURRENT_TIMESTAMP()
- CURRENT_USER()
- CURTIME()
- DATABASE()
- DATE(par1)
- DATE_ADD(par1, par2)
- DATEDIFF(par1, par2)
- DATE_FORMAT(par1, par2)
- DATE_SUB(par1, par2)
- DAY(par1)
- DAYNAME(par1)
- DAYOFMONTH(par1)
- DAYOFWEEK(par1)
- DAYOFYEAR(par1)
- DEFAULT()
- DEGREES(par1)
- EXP(par1)
- FLOOR(par1)
- FORMAT(par1, par2)
- FOUND_ROWS()
- FROM_DAYS(par1)
- GET_FORMAT(par1, par2)
- GREATEST(par1, par2, ...)
- HEX(par1)
- HOUR(par1)
- IF(par1, par2, par3)
- IFNULL(par1, par2)
- INSERT(par1, par2, par3, par4)
- INSTR(par1, par2)
- INTERVAL(par, par2, par3, ...)
- ISNULL(par1)
- LAST_DAY(par1)
- LCASE(par1)
- LEAST(par1, par2, ...)
- LEFT(par1, par2)
- LENGTH(par1)
- LN(par1)
- LOCALTIME()
- LOCALTIMESTAMP()
- LOCATE(par1, par2, par3)
- LOG(par1)
- LOG(par1, par2)
- LOG2(par1)
- LOG10(par1)
- LOWER(par1)
- LPAD(par1, par2, par3)
- LTRIM(par1)
- MAKEDATE(par1, par2)
- MAKETIME(par1, par2, par3)
- MICROSECOND(par1)
- MID(par1, par2, par3)
- MINUTE(par1)
- MOD(par1)
- MONTH(par1)
- MONTHNAME
- NOW()
- NULLIF(par1, par2)
- OCT(par1)
- OCTET_LENGTH(par1)
- ORD(par1)
- PERIOD_ADD(par1, par2)
- PERIOD_DIFF(par1, par2)
- PI()
- POWER(par1, par2)
- QUARTER
- RADIANS(par1)
- RAND(par1)
- REPEAT(par1, par2)
- REPLACE(par1, par2, par3)
- REVERSE(par1)
- RIGHT(par1, par2)
- ROUND(par1, par2)
- RPAD(par1, par2, par3)
- RTRIM(par1)
- SECOND(par1)
- SEC_TO_TIME(par1)
- SESSION_USER()
- SIGN(par1)
- SIN(par1)
- SOUNDEX(par1)
- SPACE(par1)
- SQRT(par1)
- STRCMP(par1, par2)
- STR_TO_DATE(par1, par2)
- SUBDATE(par1, par2)
- SUBSTRING(par1, par2, par3)
- SUBSTRING(par1 FROM par2 FOR par3)
- SUBSTRING_INDEX(par1, par2, par3)
- SUBTIME(par1, par2)
- SYSDATE()
- SYSTEM_USER()
- TAN(par1)
- TIME()
- TIMEDIFF(par1, par2)
- TIME_FORMAT(par1, par2)
- TIMESTAMP(par1, par2)
- TIMESTAMPADD(par1, par2, par3)
- TIMESTAMPDIFF(par1, par2, par3)
- TIME_TO_SEC(par1)
- TO_DAYS(par1)
- TRIM(par1)
- TRUNCATE(par1, par2)
- UCASE(par1)
- UNHEX(par1)
- UPPER(par1)
- USER()
- UTC_DATE()
- UTC_TIME()
- UTC_TIMESTAMP()
- UUID()
- VERSION()
- WEEK(par1)
- WEEKDAY(par1)
- WEEKOFYEAR(par1)
- YEAR(par1)
- YEARWEEK(par1, par2)
-
C. Bibliography
- D. About the CD-ROM
Product information
- Title: Introduction to SQL: Mastering the Relational Database Language, Fourth Edition/20th Anniversary Edition
- Author(s):
- Release date: September 2006
- Publisher(s): Addison-Wesley Professional
- ISBN: 0321305965
You might also like
book
Learn SQL Database Programming
Learn everything you need to know to build efficient SQL queries using this easy-to-follow beginner's guide …
book
Getting Started with SQL
Businesses are gathering data today at exponential rates and yet few people know how to access …
book
Effective SQL: 61 Specific Ways to Write Better SQL, First Edition
“Given the authors’ reputations, I expected to be impressed. I was blown away! . . . …
book
SQL for Data Analysis
With the explosion of data, computing power, and cloud data warehouses, SQL has become an even …