
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. Could you write an SQL query to find employees who have worked at least once in every programming department in the company? And be sure it’s correct? Why is proper column naming so important? Nulls in the database cause wrong answers. Why? What you can do about it? How can image relations help you formulate complex SQL queries? SQL supports "quantified comparisons," but they’re better avoided. Why? And how? Database theory and practice have evolved considerably since Codd first defined the relational model, back in 1969. This book draws on decades of experience to present the most up to date treatment of the material available anywhere. Anyone with a modest to advanced background in SQL can benefit from the insights it contains. The book is product independent.
- Database in Depth, O'Reily (2005)
- Relational Theory for Computer Professionals, O'Reilly (2013)
- SQL and Relational Theory, 3rd Ed, O'Reily (2015)
- Database Design and Relational Theory, 2nd Ed, Apress (2019)
It completely changed how I use SQL. Before reading it, I had about a decade of experience with SQL. I didn't really understand the theory underneath. I also didn't understand how to write SQL in a way that adheres to the theory.
You can think of this book as being the closest we have to "SQL: The Good Parts".
1) SQL is not entirely faithful to the underlying logical principles of the relational model. Chris Date's "Database in Depth: Relational Theory for Practitioners"[0] or "SQL and Relational Theory: How to Write Accurate SQL Code"[1] are good texts that go into this in detail. There's plenty of stuff online if you search for it. For a very brief example of criticisms, you can take a look at Wikipedia: (https://en.wikipedia.org/wiki/SQL#Criticisms).
[0]: https://www.goodreads.com/book/show/573821.Database_in_Depth
[1]: https://www.goodreads.com/book/show/6219481-sql-and-relation...
2) Most SQL systems provide a 1-to-1 mapping of tables to underlying storage structure which places limits on performance, while relations are logical and independent of the implementation. Other than indexing strategies, there hasn't been a lot of work in production systems to truly abstract storage from logical representation. They've been kind of stuck in their thinking. This second point isn't as important as the first, however, and more off-topic with respect to your question.
Just need a good SQL reference? 'The Art of SQL' or 'SQL and Relational Theory'
Are you not entertained? Fine, choke on this : http://en.wikipedia.org/wiki/The_Third_Manifesto