The Division Operator
Division answers questions containing the word every. It is the hardest operator to recognise and the easiest to verify, and it can always be rewritten using difference and product.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
Division answers questions of the form which X are related to all Y? Whenever a question contains every, all or each and every, division is the operator being asked for.
| Question | Operator |
|---|---|
| Which students take some Computing course? | Join |
| Which students take no Computing course? | Anti join |
| Which students take every Computing course? | Division |
Definition
NOTATION R divided by S
Requirement: the attributes of S must be a SUBSET of the
attributes of R.
R has attributes ( A, B )
S has attributes ( B )
R / S has attributes ( A )
Result: every value of A that appears in R paired with
EVERY value of B present in S.Worked example
ENROL ( roll_no, code ) CS_COURSE ( code )
+---------+--------+ +--------+
| 21 | CS201 | | CS201 |
| 21 | CS202 | | CS202 |
| 21 | EC101 | +--------+
| 22 | CS201 |
| 22 | CS202 | "Which students take EVERY
| 23 | CS201 | Computing course?"
| 24 | EC101 |
+---------+--------+
ENROL / CS_COURSE
STEP 1 list what each student takes
21 -> { CS201, CS202, EC101 }
22 -> { CS201, CS202 }
23 -> { CS201 }
24 -> { EC101 }
STEP 2 required set from S = { CS201, CS202 }
STEP 3 keep every student whose set CONTAINS the required set
21 { CS201, CS202, EC101 } contains it -> YES
22 { CS201, CS202 } contains it -> YES
23 { CS201 } missing CS202 -> no
24 { EC101 } missing both -> no
RESULT
+---------+
| roll_no |
+---------+
| 21 |
| 22 |
+---------+
Note that student 21 also takes EC101. Extra courses do
NOT disqualify - division tests CONTAINMENT, not equality.That last line is the most common misunderstanding. Division asks whether the required set is contained, not whether the two sets are identical.
Division expressed with primitives
Division is not primitive. The rewrite is worth learning because it explains why the operator works.
R ( A, B ) divided by S ( B )
R / S = PROJECT[A](R) - PROJECT[A]( ( PROJECT[A](R) x S ) - R )
Read it from the inside out:
PROJECT[A](R) every candidate student
... x S every candidate paired with every
REQUIRED course - the pairs that
WOULD have to exist
( ... ) - R the required pairs that DO NOT exist
= evidence of a missing course
PROJECT[A]( ... ) the students who are missing something
PROJECT[A](R) - ... all candidates MINUS the deficient ones
= the students missing nothing Tracing it on the sample data
PROJECT[roll_no](ENROL) = { 21, 22, 23, 24 }
that x CS_COURSE = 21-CS201, 21-CS202,
22-CS201, 22-CS202,
23-CS201, 23-CS202,
24-CS201, 24-CS202
minus ENROL (keep pairs NOT in ENROL)
= 23-CS202, 24-CS201, 24-CS202
PROJECT[roll_no] of that = { 23, 24 } deficient
{ 21,22,23,24 } - { 23,24 } = { 21, 22 } ANSWER
Same result as the direct method, which is the check.Recognising division in a question
| Wording | Meaning |
|---|---|
| Students who take all Computing courses | Division |
| Suppliers who supply every part | Division |
| Customers who bought every product in a category | Division |
| Employees who worked on all projects of a department | Division |
| Students who take at least one Computing course | Join, not division |
| Students who take exactly the Computing courses and nothing else | Division plus a further condition — division alone permits extras |
Verifying an answer
Division answers are easy to check by hand, so always check.
- Write out the set of related values for each candidate.
- Write out the required set from the divisor.
- Keep a candidate only if its set contains every required value.
- Confirm that extra values did not disqualify anyone.
Common mistakes
- Requiring the sets to be equal. Extra values are allowed.
- Dividing when the attributes of S are not a subset of R. The operation is undefined.
- Confusing it with a join. A join answers some, division answers every.
- Forgetting the result attributes. They are the attributes of R that are not in S.
- Assuming an empty divisor gives an empty result. If S is empty, every candidate trivially satisfies the condition, so all of them qualify.
Exam and interview questions
- Define division and state the requirement on the attributes.
- Express division using only primitive operators, and explain each step.
- Give three questions in English that require division.
- Does a student taking extra courses still qualify? Explain.
- What are the attributes of the result of R(A,B,C) divided by S(C)?
Practice
- Given SUPPLY ( supplier, part ) and PART ( part ), compute the suppliers who supply every part, by hand.
- Add one row to the ENROL example so that student 23 also qualifies, and confirm the result changes.
- Write the primitive expression for suppliers supplying every part, and trace it step by step.
- Explain in three sentences why the rewrite works by finding what is missing.
Conclusion
Division answers every questions. It tests containment, not equality, so extra values are fine. It is derived from projection, product and difference by finding the required pairs that are absent, and any answer can be verified by hand in four steps.