SQL and Relational Theory:
How to write accurate SQL code
SQL is ubiquitous. But SQL is complicated, difficult, and error prone (much more so than SQL advocates would have you believe), and testing can never be exhaustive. So to have any hope of writing correct SQL, you must follow some discipline. What discipline? Answer: The discipline of using SQL relationally. But what does this mean? Isn't SQL relational anyway?
Well, of course SQL is the standard language for use with relational databases - but that doesn't make it relational! The sad truth is, SQL departs from relational theory in all too many ways; duplicate rows and nulls provide two obvious examples, but they're not the only ones. Thus, systems based on SQL give you rope to hang yourself, as it were. So if you don't want to hang yourself, you need to understand relational theory (what it is and why); you need to know about SQL's departures from that theory; and you need to know how to avoid the problems they can cause. In a word, you need to use SQL relationally. Then you can behave as if SQL truly were relational, and you can enjoy the benefits of working with what is, in effect, a truly relational system.
Of course, a seminar like this wouldn't be needed if everyone already used SQL relationally - but they don't. On the contrary, there's a huge amount of bad practice to be observed in current SQL usage. Such practice is even recommended in textbooks and other publications, by writers who really ought to know better; in fact, a review of the literature in this regard is a pretty dispiriting exercise. The relational model first saw the light of day in 1969 - yet here we are, almost 40 years later, and it still doesn't seem to be very well understood by the database community at large. Partly for such reasons, this seminar uses the relational model itself as an organizing principle; it discusses various features of the model in depth, and shows in every case how best to use SQL to implement the feature in question. Note: Classroom exercises are an integral part of the seminar, and attendee discussion and interaction are encouraged.
What you will learn
- How relational principles provide SQL's logical underpinnings
- The breadth and depth of those principles
- How to formulate complex SQL code with confidence that it's correct
- Generally, be able to use SQL relationally
- Setting the scene
- Types and domains
- Tuples and relations, rows and tables
- No duplicates, no nulls
- Base relvars, base tables
- SQL and relational algebra I: The original operators
- SQL and relational algebra II: Additional operators
- SQL and constraints
- SQL and views
- SQL and logic I: Relational calculus
- SQL and logic II: Using logic to write SQL code
- Further SQL topics
- The relational model
- Database design theory