You are previewing SQL and Relational Theory, 3rd Edition.
O'Reilly logo
SQL and Relational Theory, 3rd Edition

Book Description

SQL is full of difficulties and traps for the unwary. You can avoid them if you understand relational theory, but only if you know how to put that theory into practice. In this book, Chris Date explains relational theory in depth, and demonstrates through numerous examples and exercises how you can apply it to your use of SQL.

This third edition has been revised, extended, and improved throughout. Topics whose treatment has been expanded include data types and domains, table comparisons, image relations, aggregate operators and summarization, view updating, and subqueries. A special feature of this edition is a new appendix on NoSQL and relational theory.

Table of Contents

    1. The relational model is much misunderstood
    2. Some remarks on terminology
    3. Principles not products
    4. A review of the original model
    5. Model vs. implementation
    6. Properties of relations
    7. Base vs. derived relations
    8. Relations vs. relvars
    9. Values vs. variables
    10. Concluding remarks
    11. Exercises
    12. Answers
    1. Types and relations
    2. Equality comparisons
    3. Data value atomicity
    4. What’s a type?
    5. Scalar vs. nonscalar types
    6. Scalar types in SQL
    7. Type checking and coercion in SQL
    8. Collations in SQL
    9. Row and table types in SQL
    10. Concluding remarks
    11. Exercises
    12. Answers
    1. What’s a tuple?
    2. Rows in SQL
    3. What’s a relation?
    4. Relations and their bodies
    5. Relations are <em xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">n</em>-dimensional-dimensional
    6. Relational comparisons
    7. TABLE_DUM and TABLE_DEE
    8. Tables in SQL
    9. Column naming in SQL
    10. Concluding remarks
    11. Exercises
    12. Answers
    1. What’s wrong with duplicates?
    2. Duplicates: further issues
    3. Avoiding duplicates in SQL
    4. What’s wrong with nulls?
    5. Avoiding nulls in SQL
    6. A remark on outer join
    7. Concluding remarks
    8. Exercises
    9. Answers
    1. Updating is set level
    2. Relational assignment
    3. More on candidate keys
    4. More on foreign keys
    5. Relvars and predicates
    6. Relations vs. types
    7. Exercises
    8. Answers
    1. Some preliminaries
    2. More on closure
    3. Restriction
    4. Projection
    5. Join
    6. Union, intersection, and difference
    7. Which operators are primitive?
    8. Formulating expressions one step at a time
    9. What do relational expressions mean?
    10. Evaluating SQL table expressions
    11. Expression transformation
    12. The reliance on attribute names
    13. Exercises
    14. Answers
    1. Exclusive union
    2. Semijoin and semidifference
    3. Extend
    4. Image relations
    5. Divide
    6. Aggregate operators
    7. Image relations revisited
    8. Summarization
    9. Summarization revisited
    10. Group, ungroup, and relation valued attributes
    11. “What if” queries
    12. A note on recursion
    13. What about ORDER BY?
    14. Exercises
    15. Answers
    1. Type constraints
    2. Type constraints in SQL
    3. Database constraints
    4. Database constraints in SQL
    5. Transactions
    6. Why database constraint checking must be immediate
    7. But doesn’t some checking have to be deferred?
    8. Constraints and predicates
    9. Miscellaneous issues
    10. Exercises
    11. Answers
    1. Views are relvars
    2. Views and predicates
    3. Retrieval operations
    4. Views and constraints
    5. Update operations
    6. What are views for?
    7. Views and snapshots
    8. Exercises
    9. Answers
    1. Why do we need logic?
    2. Simple and compound propositions
    3. Simple and compound predicates
    4. Quantification
    5. Relational calculus
    6. More on quantification
    7. Some equivalences
    8. Concluding remarks
    9. Exercises
    10. Answers
    1. Some transformation laws
    2. Example 1: Logical implication
    3. Example 2: Universal quantification
    4. Example 3: Implication and universal quantification
    5. Example 4: Correlated subqueries
    6. Example 5: Naming subexpressions
    7. Example 6: More on naming subexpressions
    8. Example 7: Dealing with ambiguity
    9. Example 8: Using COUNT
    10. Example 9: Another variation
    11. Example 10: UNIQUE quantification
    12. Example 11: ALL or ANY comparisons
    13. Example 12: GROUP BY and HAVING
    14. Exercises
    15. Answers
    1. SELECT *
    2. Explicit tables
    3. Dot qualification
    4. Range variables
    5. Subqueries
    6. “Possibly nondeterministic” expressions
    7. Empty sets
    8. A simplified BNF grammar
    9. Exercises
    10. Answers
    1. The relational model vs. others
    2. The significance of theory
    3. The relational model defined
    4. Database variables
    5. Objectives of the relational model
    6. Some database principles
    7. What remains to be done?
    1. Vertical decomposition
    2. Horizontal decomposition
    3. What do the shaded entries mean?
    4. Constraints
    5. Queries
    6. More on predicates
    7. Exercises
    8. Answers
    1. Functional segmentation
    2. Sharding
    3. Eventual consistency
    4. The Fernandez interview