First page Back Continue Last page Graphics

SQL (Structured Query Language)


Notes:

Ideally we would like to study only the relational algebra and the tuple calculus. But in the “real world” a different query language is used: SQL, or the Stuctured Query Language.
SQL is a declarative language, like the tuple calculus. But it looks a bit different, giving it a more procedural look and feel. It is easy to translate most SQL queries to the relational algebra.
For a mathematician SQL is a nightmare: it considers singleton sets and single values to be the same, and set membership and equality can be mixed almost freely.
SQL also has some interesting complications. In SQL tables or query results can contain duplicate tuples; they are bags or multisets, not sets. This implies that we need a variation on the set theory in order to understand how SQL works.
SQL also has a mechanism for dealing with missing information. It uses a special null value to indicate that a value is unknown or may not even exist. SQL uses a three-valued logic in order to deal with null values.
No matter how difficult SQL is, we need to learn it because it is the most used query language in relational database systems.
If you think you already know SQL from a previous course, then think how you would write the query: “Give the customers who have, for each branch where they have an account or loan, more money in accounts at that branch than money borrowed from that branch”. Chances are you never tried a query this complicated before and you don't yet know how to translate it to SQL.