An Introduction to Relational Database Theory (Hugh Darwen)
Total Page:16
File Type:pdf, Size:1020Kb
An Introduction to Relational Database Theory Hugh Darwen Download free books at Hugh Darwen An Introduction to Relational Database Theory Download free eBooks at bookboon.com 2 An Introduction to Relational Database Theory 4th edition © 2014 Hugh Darwen & bookboon.com ISBN 978-87-403-0777-1 This book is dedicated to the researchers at IBM United Kingdom’s Scientific Centre, Peterlee, UK, in the 1970s, who designed and implemented the relational database language, ISBL, that has been my guide ever since. Download free eBooks at bookboon.com 3 An Introduction to Relational Database Theory Contents Contents Preface 9 1 Introduction 14 1.1 Introduction 14 1.2 What Is a Database? 14 1.3 “Organized Collection of Symbols” 15 1.4 “To Be Interpreted as a True Account” 15 1.5 “Collection of Variables” 17 1.6 What Is a Relational Database? 18 1.7 “Relation” Not Equal to “Table” 19 1.8 Anatomy of a Relation 21 1.9 What Is a DBMS? 22 1.10 What Is a Database Language? 23 1.11 What Does a DBMS Do? 23 1.12 Creating and Destroying Variables 24 1.13 Taking Note of Integrity Rules 26 Download free eBooks at bookboon.com 4 Click on the ad to read more An Introduction to Relational Database Theory Contents 1.14 Taking Note of Authorisations 27 1.15 Updating Variables 28 1.16 Providing Results of Queries 31 EXERCISE 32 2 Values, Types, Variables, Operators 33 2.1 Introduction 33 2.2 Anatomy of A Command 33 2.3 Important Distinctions 36 2.4 A Closer Look at a Read-Only Operator (+) 37 2.5 Read-only Operators in Tutorial D 37 360° 2.6 What Is a Type? 41 2.7 What Is a Type Used For? 42 2.8 The Type of a Relation 42 thinking 2.9 Relation Literals 360° 44 . 2.10 Types and Representations 47 2.11 What Is a Variable? thinking 49 2.12 Updating a Variable . 51 2.13 Conclusion 54 EXERCISES 55 360° thinking . 360° thinking. Discover the truth at www.deloitte.ca/careers Discover the truth at www.deloitte.ca/careers © Deloitte & Touche LLP and affiliated entities. Discover the truth at www.deloitte.ca/careers © Deloitte & Touche LLP and affiliated entities. Download free eBooks at bookboon.com © Deloitte & Touche LLP and affiliated entities. Discover the truth5 at www.deloitte.ca/careersClick on the ad to read more © Deloitte & Touche LLP and affiliated entities. An Introduction to Relational Database Theory Contents 3 Predicates and Propositions 64 3.1 Introduction 64 3.2 What Is a Predicate? 64 3.3 Substitution and Instantiation 69 3.4 How a Relation Represents an Extension 70 3.5 Deriving Predicates from Predicates 76 EXERCISES 86 4 Relational Algebra—The Foundation 88 4.1 Introduction 88 4.2 Relations and Predicates 91 4.3 Relational Operators and Logical Operators 92 4.4 JOIN and AND 92 4.5 RENAME 96 4.6 Projection and Existential Quantification 99 4.7 Restriction and AND 105 4.8 Extension and AND 108 4.9 UNION and OR 110 4.10 Semidifference and NOT 113 4.11 Concluding Remarks 116 EXERCISES 117 GOT-THE-ENERGY-TO-LEAD.COM We believe that energy suppliers should be renewable, too. We are therefore looking for enthusiastic new colleagues with plenty of ideas who want to join RWE in changing the world. Visit us online to find out what we are offering and how we are working together to ensure the energy of the future. Download free eBooks at bookboon.com 6 Click on the ad to read more An Introduction to Relational Database Theory Contents 5 Building on The Foundation 121 5.1 Introduction 121 5.2 Semijoin and Composition 122 5.3 Aggregate Operators 127 5.4 Relations within a Relation 131 5.5 Using Aggregate Operators with Nested Relations 132 5.6 SUMMARIZE 134 5.7 GROUP and UNGROUP 136 5.8 WRAP and UNWRAP 140 5.9 Relation Comparison 143 5.10 Other Operators on Relations and Tuples 148 EXERCISES 149 6 Constraints and Updating 150 6.1 Introduction 150 6.2 A Closer Look at Constraints and Consistency 151 6.3 Expressing Constraint Conditions 152 6.4 Useful Shorthands for Expressing Constraints 160 6.5 Updating Relvars 165 EXERCISES 174 By 2020, wind could provide one-tenth of our planet’s Brain power electricity needs. Already today, SKF’s innovative know- how is crucial to running a large proportion of the world’s wind turbines. Up to 25 % of the generating costs relate to mainte- nance. These can be reduced dramatically thanks to our systems for on-line condition monitoring and automatic lubrication. We help make it more economical to create cleaner, cheaper energy out of thin air. By sharing our experience, expertise, and creativity, industries can boost performance beyond expectations. Therefore we need the best employees who can meet this challenge! The Power of Knowledge Engineering Plug into The Power of Knowledge Engineering. Visit us at www.skf.com/knowledge Download free eBooks at bookboon.com 7 Click on the ad to read more An Introduction to Relational Database Theory Contents 7 Database Design I: Projection-Join Normalization 175 7.1 Introduction 175 7.2 Avoiding Redundancy 175 7.3 Join Dependencies 177 7.4 Fifth Normal Form 185 7.5 Functional Dependencies 192 7.6 Keys 198 7.7 The Role of FDs and Keys in Optimization 199 7.8 Boyce-Codd Normal Form (BCNF) 201 7.9 JDs Not Arising from FDs 211 EXERCISES 216 8 Database Design II: Other Issues 219 8.1 Group-Ungroup and Wrap-Unwrap Normalization 219 8.2 Restriction-Union Normalization 226 8.3 Surrogate Keys 227 8.4 Representing “Entity Subtypes” 230 Appendix A: References and Bibliography 233 With us you can shape the future. Every single day. For more information go to: www.eon-career.com Your energy shapes the future. Download free eBooks at bookboon.com 8 Click on the ad to read more An Introduction to Relational Database Theory Preface Preface This book introduces you to the theory of relational databases, focusing on the application of that theory to the design of computer languages that properly embrace it. The book is intended for those studying relational databases as part of a degree course in Information Technology (IT). Relational database theory, originally proposed by Edgar F. Codd in 1969, is a topic in Computer Science. Codd’s seminal paper (1970) was entitled A Relational Model of Data for Large Shared Data Banks (reference [5] in Appendix A). An introductory course on relational databases offered by a university’s Computer Science (or similarly named) department is typically broadly divided into a theory component and what we might call an “industrial” component. The “industrial” component typically teaches the language, SQL (Structured Query Language), that is widely used in the industry for database purposes, and it might also teach other topics of current significance in the industry. Although this book is only about the theory, I hope it will be interesting and helpful to you even if your course’s main thrust is industrial. In the companion book SQL: A Comparative Survey I show how the concepts covered in this book are treated in SQL, along with historical notes explaining how and when the treatments in question arose in the official version of that language. (Aside: SQL doesn’t officially stand for anything, though it is usually assumed to stand for Structured Query Language. And the standard pronunciation is “ess-cue-ell”, not “sequel”, so a DBMS that supports it is an SQL DBMS, not a SQL DBMS.) The book is directly based on a course of nine lectures that was delivered annually from 2004 to 2011 to undergraduates at the University of Warwick, England, as part of a 14-lecture module entitled Fundamentals of Relational Databases. The remaining five lectures of that module were on SQL. We encouraged the students to compare and contrast SQL with what they had learned in the theory part. We explained that study of the theory, and an example of a computer language based on that theory, should: • enable them to understand the technology that is based on it, and how to use that technology (even if it is only loosely based on the theory, as is the case with SQL systems); • provide a basis for evaluating and criticizing the current state of the art; • illustrate of some of the generally accepted principles of good computer language design; • equip those who might be motivated in their future careers to bring about change for the better in the database industry. Download free eBooks at bookboon.com 9 An Introduction to Relational Database Theory Preface Examples and exercises in this book all use a language, Tutorial D, invented by the author and C.J. Date for the express purpose of teaching the subject matter at hand. Implementations of Tutorial D, which is described in reference [12], are available as free software on the Web. The one we use at the University of Warwick is called Rel, made by Dave Voorhis of the University of Derby. Rel is freely available at http://dbappbuilder.sourceforge.net/Rel.html. This book is accompanied by Exercises in Relational Database Theory, in which the exercises given at the end of each chapter (except the last) are copied and a few further exercises have been added. Sample solutions to all the exercises are provided and the reader is strongly recommended to study these solutions (preferably after attempting the exercises!). The book consists of eight chapters and two appendixes, as follows.