Relational calculus in general is a way to say WHAT we want without describing HOW to get what we want, making this a declarative/nonprocedural language
This and relational algebra are very similar in that we can write all the same queries and get the same output, but the way we go about it is different
Since there’s 2 dimensions of relations (tuples and domain), there’s 2 corresponding types of relational calculus: tuple relational calculus and domain relational calculus
Tuple relational calculus takes the following general form
\[\{t | \text{Condition}(t)\} \\ t \text{ is a tuple and Condition}(t) \text{ is a boolean expression} \\ \{t.fName,t.lName|\text{EMPLOYEE(t) AND t.Age > 5}\}\]In general, we need to specify three things
For upcoming examples, we’ll use the following tables
For joins, we can make use of the existential qualifier and universal qualifier from 2209
\[(\exists t)(F) \\ (\forall t)(F) \\ \{t.fName|\text{EMPLOYEE}(t)\text{ AND } (\exists d) \text{ DEPARTMENT(d) AND} \\ \text{d.dNumber = t.DNO}\}\]You can also do division but it’s not tested and tbh I don’t feel like writing it down lmao
Just like we can do calculus on tuples, we can do the same for domains
Instead of grabbing specific tuples, we instead use the domains as our parameters
\[\{x_1,x_2,...,x_n|COND(x_1,x_2,...,x_n,x_{n+1},...,x_{n+m})\} \\\]For example…
\[\{u,v|(\exists q)(\exists s) (\text{EMPLOYEE(qrstuvwxyz) AND q="John"}) \\ \text{AND s="Mortensen"} \} \\ \{u,v|\text{EMPLOYEE("John",r,"Mortensen",t,u,v,w,x,y,z)}\}\]We can do joins in much of the same way
For example, the following gets the first name of every employee who has no dependents
\[\{q|(\exists t)(\text{EMPLOYEE(qrstuvwxyz) AND (NOT }(\exists l)\\\text{ DEPENDENT(lmnop) AND t=l)))}\}\]Query by Example (QBE) is a user friendly language developed by IBM that uses domain calculus to make queries for people that have little to no background in SQL
In QBE, we take fields matched to tables and give them a condition
For example, the following QBE in MS Access finds all data about employees with the last name Simpson
Equivalent SQL query
We can also use our aggregate functions (averages, maximums, etc.) in Total without any SQL
EER Diagrams are just like ER diagrams, except we introduce inheritance from OOP
The idea is that, if we think of entities as objects, then the entity type is an object class
From here, we can introduce subclasses (subtypes) that inherit properties from their superclass, just like we can in Java
EER in practice
Note that entities can’t ONLY be part of the subclass, but it can be only part of the superclass like e5
We don’t JUST have to do disjoints; we can have overlap, where one member is in multiple subclasses
We talked about 7 steps for converting ER diagrams to tables, but now we can introduce an 8th rule:
Convert each specialization with $m$ subclasses ${S_1,S_2,…,S_m}$ and superclass $C$, where the attributes of $C$ are ${k,a_1,…,a_n}$ and $k$ is the primary key, into relations schemes using one of the four following options