SQL and Relational Theory
How to Write Accurate SQL Code SECOND EDITION
C. J. Date
sql_final.pdf 1
12/8/11 2:33:04 PM
SQL and Relational Theory: How to Write Accurate SQL Code (2nd edition) by C. J. Date Copyright © 2012 C. J. Date. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribooksonline.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or
[email protected] Printing History: January 2009: First Edition. December 2011: Second Edition. Revision History: 2011-12-08 First release See http://oreilly.com/catalog/errata.csp?isbn= 9781449316402 for release details.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. SQL and Relational Theory: How to Write Accurate SQL Code and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein.
ISBN: 978-1-449-31640-2 [LSI]
sql_final.pdf 2
12/8/11 2:33:05 PM
Those who are enamored of practice without theory are like a pilot who goes into a ship without rudder or compass and never has any certainty where he is going Practice should always be based upon a sound knowledge of theory. —Leonardo da Vinci (1452–1519) The trouble with people is not that they don’t know but that they know so much that ain’t so. —Josh Billings (1818–1885) Languages die... mathematical ideas do not. —G.
H. Hardy (1877–1947)
Unfortunately, the gap between theory and practice is not as wide in theory as it is in practice. —Anon.
These are my principles. If you don’t like them, I have others. —Groucho
Marx (1890–1977)
There is no royal road to geometry. —Euclid (c. 365–275 BCE), attrib.
———
®®®®® ———
To all those who think an exercise like this one is worthwhile, and in particular to the memory of Lex de Haan, who is very much missed
sql_final.pdf 3
12/8/11 2:33:05 PM
About the Author C. J. Date is an independent author, lecturer, researcher, and consultant, specializing in relational database technology. He is best known for his book An Introduction to Database Systems, 8th edition (Addison-Wesley, 2004), which has sold some 850,000 copies at the time of writing and is used by several hundred colleges and universities worldwide. He is also the author of many other books on database management, including most recently:
From Addison-Wesley: Databases, Types, and the Relational Model: The Th