Book description
“Given the authors’ reputations, I expected to be
impressed. I was blown away! . . . Most SQL books sit on my shelf.
This one will live on my desk.”
–Roger Carlson, Microsoft Access MVP (2006-2015)
“Rather than stumble around reinventing wheels or catching
glimpses of the proper approaches, do yourself a favor: Buy this
book.”
—Dave Stokes, MySQL Community Manager, Oracle
Corporation
Effective SQL brings together practical solutions and
insights so you can solve complex problems with SQL and design
databases that simplify data management in the future. It’s
the only modern book that brings together advanced best practices
and realistic example code for all of these versions of SQL: IBM
DB2, Microsoft Access, Microsoft SQL Server, MySQL, Oracle
Database, and PostgreSQL.
Drawing on their immense experience as world-class database
consultants and instructors, the authors identify 61 proven
approaches to writing better SQL. Wherever SQL versions vary, the
authors illuminate the key nuances, so you can get the most out of
whatever version you prefer. This full-color guide provides clear,
practical explanations; expert tips; and plenty of usable code.
Going far beyond mere syntax, it addresses issues ranging from
optimizing database designs to managing hierarchies and metadata.
If you already know SQL’s basics, this guide will help you
become a world-class SQL problem-solver.
Craft better logical data models, and fix flawed models
Implement indexes that improve query performance
Handle external data from sources you don’t control
Extract and aggregate the information you need, as efficiently as possible
Write more flexible subqueries
Analyze and retrieve metadata using your database platform of choice
Use Cartesian Products and Tally Tables to solve problems you can’t address with conventional JOINs
Model hierarchical data: managing SQL’s tradeoffs and shortcomings
Table of contents
- About This E-Book
- Title Page
- Copyright Page
- Dedication Page
- Contents
- Foreword
- Acknowledgments
- About the Authors
- About the Technical Editors
- Introduction
-
1. Data Model Design
- Item 1: Verify That All Tables Have a Primary Key
- Item 2: Eliminate Redundant Storage of Data Items
- Item 3: Get Rid of Repeating Groups
- Item 4: Store Only One Property per Column
- Item 5: Understand Why Storing Calculated Data Is Usually a Bad Idea
- Item 6: Define Foreign Keys to Protect Referential Integrity
- Item 7: Be Sure Your Table Relationships Make Sense
- Item 8: When 3NF Is Not Enough, Normalize More
- Item 9: Use Denormalization for Information Warehouses
-
2. Programmability and Index Design
- Item 10: Factor in Nulls When Creating Indexes
- Item 11: Carefully Consider Creation of Indexes to Minimize Index and Data Scanning
- Item 12: Use Indexes for More than Just Filtering
- Item 13: Don’t Go Overboard with Triggers
- Item 14: Consider Using a Filtered Index to Include or Exclude a Subset of Data
- Item 15: Use Declarative Constraints Instead of Programming Checks
- Item 16: Know Which SQL Dialect Your Product Uses and Write Accordingly
- Item 17: Know When to Use Calculated Results in Indexes
- 3. When You Can’t Change the Design
-
4. Filtering and Finding Data
- Item 22: Understand Relational Algebra and How It Is Implemented in SQL
- Item 23: Find Non-matches or Missing Records
- Item 24: Know When to Use CASE to Solve a Problem
- Item 25: Know Techniques to Solve Multiple-Criteria Problems
- Item 26: Divide Your Data If You Need a Perfect Match
- Item 27: Know How to Correctly Filter a Range of Dates on a Column Containing Both Date and Time
- Item 28: Write Sargable Queries to Ensure That the Engine Will Use Indexes
- Item 29: Correctly Filter the “Right” Side of a “Left” Join
-
5. Aggregation
- Item 30: Understand How GROUP BY Works
- Item 31: Keep the GROUP BY Clause Small
- Item 32: Leverage GROUP BY/HAVING to Solve Complex Problems
- Item 33: Find Maximum or Minimum Values Without Using GROUP BY
- Item 34: Avoid Getting an Erroneous COUNT() When Using OUTER JOIN
- Item 35: Include Zero-Value Rows When Testing for HAVING COUNT(x) < Some Number
- Item 36: Use DISTINCT to Get Distinct Counts
- Item 37: Know How to Use Window Functions
- Item 38: Create Row Numbers and Rank a Row over Other Rows
- Item 39: Create a Moving Aggregate
- 6. Subqueries
- 7. Getting and Analyzing Metadata
-
8. Cartesian Products
- Item 47: Produce Combinations of Rows between Two Tables and Flag Rows in the Second That Indirectly Relate to the First
- Item 48: Understand How to Rank Rows by Equal Quantiles
- Item 49: Know How to Pair Rows in a Table with All Other Rows
- Item 50: Understand How to List Categories and the Count of First, Second, or Third Preferences
-
9. Tally Tables
- Item 51: Use a Tally Table to Generate Null Rows Based on a Parameter
- Item 52: Use a Tally Table and Window Functions for Sequencing
- Item 53: Generate Multiple Rows Based on Range Values in a Tally Table
- Item 54: Convert a Value in One Table Based on a Range of Values in a Tally Table
- Item 55: Use a Date Table to Simplify Date Calculation
- Item 56: Create an Appointment Calendar Table with All Dates Enumerated in a Range
- Item 57: Pivot Data Using a Tally Table
- 10. Modeling Hierarchical Data
- Appendix. Date and Time Types, Operations, and Functions
- Index
- Code Snippets
Product information
- Title: Effective SQL: 61 Specific Ways to Write Better SQL, First Edition
- Author(s):
- Release date: December 2016
- Publisher(s): Addison-Wesley Professional
- ISBN: 9780134579078
You might also like
book
Python Crash Course, 2nd Edition
This is the second edition of the best selling Python book in the world. Python Crash …
book
SQL in 24 Hours, Sams Teach Yourself, 7th Edition
In just 24 lessons of one hour or less, Sams Teach Yourself SQL in 24 Hours …
book
Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow, 3rd Edition
Through a recent series of breakthroughs, deep learning has boosted the entire field of machine learning. …
book
A Guide to the Project Management Body of Knowledge (PMBOK® Guide) – Seventh Edition and The Standard for Project Management (ENGLISH)
PMBOK® Guide is the go-to resource for project management practitioners. The project management profession has significantly …