Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Â
07.05 division
1.
2. Division
ï Division is not essential operation ; just a useful shorthand.
ï Also true of joins, but joins are so common that systems implement
joins specially. Division is NOT implemented in SQL.
ï Not supported as a primitive operator, but useful for many
expressing queries
ï Precondition: in A/B, the attributes in B must be included in the
schema for A. Also, the result has attributes A-B.
ï SALES(supId, prodId);
ï PRODUCTS(prodId);
ï Relations SALES and PRODUCTS must be built using projections.
ï SALES/PRODUCTS: the ids of the suppliers supplying ALL
products
3. ï 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
ï 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
4. Student Task
Fred Database1
Fred Database2
Fred Compiler1
Eugene Database1
Eugene Compiler1
Sarah Database1
Sarah Database2
Completed DBProject
Task
Database1
Database2
Completed
Ă·
DBProject
Student
Fred
Sarah
8. ï Suppose that employees of the company are assigned
to some professional courses; each employee follows
several courses and each course is taken by several
employees
ï Information about courses and which employee takes
which course can be represented by the following
relations
ï Takes (Emp#, Course#)
ï Courses (Course#, Topic, Weeks)
9. ï Assume that these two relations have the following
content
Emp# Course#
7369 10
7369 20
7369 30
7782 10
7782 40
Course# Topics Weeks
20 CAD 5
10 DB 3
30 DB 2
40 OS 4
Takes Courses
10. ï Consider the following query: âdetermine the emp# of
the employees taking all the courses with topic DBâ
(Q1)
ï The course# of the courses relevant to the query is
obtained through the following expression:
R1 = â Course# (Ï Topic=âDBâ) (Courses))
The result of such query is {10, 30}
11. ï The result of query Q1 is represented by all the
employees that appear in the Takes relation with each
of the course numbers retrieved by query R1
ï The correct result of Q1 is thus {7369}
ï The operation that allows one to execute such query is
the division
12. ï Let R and S be relations; let UR and US be the attribute
ï sets of R and S, respectively, and such that UR US
ï The division operation is denoted as
R Ă· S
and is expressed as follows
ï â(UR -US) (R) - â (UR -US) ((â (UR âUS) (R) X S) â R)
ï The expression on the right side of the â sign
determines all tuples of R that are not associated with
at least a tuple of S
13. ï Query Q1 is thus expressed as follows:
Takes Ă· â Course# (Ï Topic=âDBâ) (Courses))
R = Takes
S = â Course# (Ï Topic=âDBâ) (Courses))
S = {10, 30}
UR = {Emp#, Course#}
Us = {Course#}