User:R3h7268/sandbox

(÷)
The division is a binary operation that is written as R ÷ S. The result consists of the restrictions of tuples in R to the attribute names unique to R, i.e., in the header of R but not in the header of S, for which it holds that all their combinations with tuples in S are present in R. For an example see the tables Completed, DBProject and their division:

If DBProject contains all the tasks of the Database project, then the result of the division above contains exactly the students who have completed both of the tasks in the Database project.

More formally the semantics of the division is defined as follows:where {a1,...,an} is the set of attribute names unique to R and t[a1,...,an] is the restriction of t to this set. It is usually required that the attribute names in the header of S are a subset of those of R because otherwise the result of the operation will always be empty.

The simulation of the division with the basic operations is as follows. We assume that a1,...,an are the attribute names unique to R and b1,...,bm are the attribute names of S. In the first step we project R on its unique attribute names and construct all combinations with tuples in S:
 * T := πa 1,...,an (R) × S

In the prior example, T would represent a table such that every Student (because Student is the unique key / attribute of the Completed table) is combined with every given Task. So Eugene, for instance, would have two rows, Eugene -> Database1 and Eugene -> Database2 in T.


 * EG: First, let's pretend that "Completed" has a third attribute called "grade". It's unwanted baggage here, so we must project it off always. In fact in this step we can drop 'Task' from R as well; the multiply puts it back on.
 * T := πStudent(R) × S // This gives us every possible desired combination, including those that don't actually exist in R, and excluding others (eg Fred | compiler1, which is not a desired combination)

In the next step we subtract R from T relation:
 * U := T &minus; R

Note that in U we have the possible combinations that "could have" been in R, but weren't.
 * EG: Again with projections - T and R need to have identical attribute names/headers.
 * U := T - πStudent,Task(R) // This gives us a "what's missing" list.

So if we now take the projection on the attribute names unique to R then we have the restrictions of the tuples in R for which not all combinations with tuples in S were present in R:
 * V := πa 1,...,an (U)
 * EG: Project U down to just the attribute in question (Student)
 * V := πStudent(R)

So what remains to be done is take the projection of R on its unique attribute names and subtract those in V:
 * W := πa 1,...,an (R) &minus; V
 * EG: W := πStudent(R) - V.

Common extensions
In practice the classical relational algebra

Common extensions
In practice the classical relational algebra