Synopses & Reviews
Understanding SQL's underlying theory is the best way to guarantee that your SQL code is correct and your database schema is robust and maintainable. On the other hand, if you're not well versed in the theory, you can fall into several traps. In SQL and Relational Theory, author C.J. Date demonstrates how you can apply relational theory directly to your use of SQL. With numerous examples and clear explanations of the reasoning behind them, you'll learn how to deal with common SQL dilemmas, such as:
- Should database access granted be through views instead of base tables?
- Nulls in your database are causing you to get wrong answers. Why? What can you do about it?
- Could you write an SQL query to find employees who have never been in the same department for more than six months at a time?
- SQL supports "quantified comparisons," but they're better avoided. Why? How do you avoid them?
- Constraints are crucially important, but most SQL products don't support them properly. What can you do to resolve this situation?
Database theory and practice have evolved since Edgar Codd originally defined the relational model back in 1969. Independent of any SQL products, SQL and Relational Theory draws on decades of research to present the most up-to-date treatment of the material available anywhere. Anyone with a modest to advanced background in SQL will benefit from the many insights in this book.
Synopsis
One of the key researchers in the field of relational databases shows readers how to program SQL in a way that avoids common errors and facilitates maintenance. The SQL database query language is full of traps for those who are not well educated in the concepts of relational databases. In this book, researcher C.J. Date explains the best practices of database coding, with clear explanations of the reasoning behind them. The book draws on decades of research to offer clear advice with plenty of examples.
About the Author
Chris Date has a stature in the database industry thats unique. He enjoys a reputation thats second to none for his ability to explain complex technical issues in a clear and understandable fashion. His previous books for OReilly include SQL and Relational Theory (2nd edition); Database Design and Relational Theory; and View Updating and Relational Theory. The present book serves as an introduction to those previous ones.
Table of Contents
Preface; Prerequisites; Database in Depth; Further Remarks on the Text; Conventions Used in This Book; Using Code Examples; Comments and Questions; Safari® Books Online; Acknowledgments; Chapter 1: Setting the Scene; 1.1 The Relational Model Is Much Misunderstood; 1.2 Some Remarks on Terminology; 1.3 Principles, Not Products; 1.4 A Review of the Original Model; 1.5 Model vs. Implementation; 1.6 Properties of Relations; 1.7 Base vs. Derived Relations; 1.8 Relations vs. Relvars; 1.9 Values vs. Variables; 1.10 Concluding Remarks; 1.11 Exercises; Chapter 2: Types and Domains; 2.1 Types and Relations; 2.2 Equality Comparisons; 2.3 Data Value Atomicity; 2.4 What's a Type?; 2.5 Scalar vs. Nonscalar Types; 2.6 Scalar Types in SQL; 2.7 Type Checking and Coercion in SQL; 2.8 Collations in SQL; 2.9 Row and Table Types in SQL; 2.10 Concluding Remarks; 2.11 Exercises; Chapter 3: Tuples and Relations, Rows and Tables; 3.1 What's a Tuple?; 3.2 Rows in SQL; 3.3 What's a Relation?; 3.4 Relations and Their Bodies; 3.5 Relations Are n-Dimensional; 3.6 Relational Comparisons; 3.7 TABLE_DUM and TABLE_DEE; 3.8 Tables in SQL; 3.9 Column Naming in SQL; 3.10 Concluding Remarks; 3.11 Exercises; Chapter 4: No Duplicates, No Nulls; 4.1 What's Wrong with Duplicates?; 4.2 Duplicates: Further Issues; 4.3 Avoiding Duplicates in SQL; 4.4 What's Wrong with Nulls?; 4.5 Avoiding Nulls in SQL; 4.6 A Remark on Outer Join; 4.7 Concluding Remarks; 4.8 Exercises; Chapter 5: Base Relvars, Base Tables; 5.1 Data Definitions; 5.2 Updating Is Set Level; 5.3 Relational Assignment; 5.4 More on Candidate Keys; 5.5 More on Foreign Keys; 5.6 Relvars and Predicates; 5.7 Relations vs. Types; 5.8 Exercises; Chapter 6: SQL and Relational Algebra I: The Original Operators; 6.1 Some Preliminaries; 6.2 More on Closure; 6.3 Restriction; 6.4 Projection; 6.5 Join; 6.6 Union, Intersection, and Difference; 6.7 Which Operators Are Primitive?; 6.8 Formulating Expressions a Step at a Time; 6.9 What Do Relational Expressions Mean?; 6.10 Evaluating SQL Table Expressions; 6.11 Expression Transformation; 6.12 The Reliance on Attribute Names; 6.13 Exercises; Chapter 7: SQL and Relational Algebra II: Additional Operators; 7.1 Semijoin and Semidifference; 7.2 Extend; 7.3 Image Relations; 7.4 Divide; 7.5 Aggregate Operators; 7.6 Image Relations bis; 7.7 Summarization; 7.8 Summarization bis; 7.9 Group and Ungroup; 7.10 "What If" Queries; 7.11 What About ORDER BY?; 7.12 Exercises; Chapter 8: SQL and Constraints; 8.1 Type Constraints; 8.2 Type Constraints in SQL; 8.3 Database Constraints; 8.4 Database Constraints in SQL; 8.5 Transactions; 8.6 Why Database Constraint Checking Must Be Immediate; 8.7 But Doesn't Some Checking Have to Be Deferred?; 8.8 Constraints and Predicates; 8.9 Miscellaneous Issues; 8.10 Exercises; Chapter 9: SQL and Views; 9.1 Views Are Relvars; 9.2 Views and Predicates; 9.3 Retrieval Operations; 9.4 Views and Constraints; 9.5 Update Operations; 9.6 What Are Views For?; 9.7 Views and Snapshots; 9.8 Exercises; Chapter 10: SQL and Logic; 10.1 Simple and Compound Propositions; 10.2 Simple and Compound Predicates; 10.3 Quantification; 10.4 Relational Calculus; 10.5 More on Quantification; 10.6 Some Equivalences; 10.7 Concluding Remarks; 10.8 Exercises; Chapter 11: Using Logic to Formulate SQL Expressions; 11.1 Some Transformation Laws; 11.2 Example 1: Logical Implication; 11.3 Example 2: Universal Quantification; 11.4 Example 3: Implication and Universal Quantification; 11.5 Example 4: Correlated Subqueries; 11.6 Example 5: Naming Subexpressions; 11.7 Example 6: More on Naming Subexpressions; 11.8 Example 7: Dealing with Ambiguity; 11.9 Example 8: Using COUNT; 11.10 Example 9: Join Queries; 11.11 Example 10: UNIQUE Quantification; 11.12 Example 11: ALL or ANY Comparisons; 11.13 Example 12: GROUP BY and HAVING; 11.14 Exercises; Chapter 12: Miscellaneous SQL Topics; 12.1 SELECT *; 12.2 Explicit Tables; 12.3 Name Qualification; 12.4 Range Variables; 12.5 Subqueries; 12.6 "Possibly Nondeterministic" Expressions; 12.7 Empty Sets; 12.8 A BNF Grammar for SQL Table Expressions; 12.9 Exercises; The Relational Model; The Relational Model vs. Others; The Relational Model Defined; Objectives of the Relational Model; Some Database Principles; What Remains to Be Done?; Database Design Theory; The Place of Design Theory; Functional Dependencies and Boyce/Codd Normal Form; Join Dependencies and Fifth Normal Form; Two Cheers for Normalization; Orthogonality; Some Remarks on Physical Design; Concluding Remarks; Exercises; Answers to Exercises; Chapter 1; Chapter 2; Chapter 3; Chapter 4; Chapter 5; Chapter 6; Chapter 7; Chapter 8; Chapter 9; Chapter 10; Chapter 11; Chapter 12; ; Suggestions for Further Reading; Colophon;