Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Relational algebra
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==== Example ==== {{col-begin|width=auto; margin:0.5em auto}} {{col-break}} {| class="wikitable" |+ ''Completed'' |- ! Student !! Task |- | Fred || Database1 |- | Fred || Database2 |- | Fred || Compiler1 |- | Eugene || Database1 |- | Eugene || Compiler1 |- | Sarah || Database1 |- | Sarah || Database2 |} {{col-break|gap=2em}} {| class="wikitable" |+ ''DBProject'' |- ! Task |- | Database1 |- | Database2 |} {{col-break|gap=2em}} {| class="wikitable" |+ ''Completed'' Γ· ''DBProject'' |- ! Student |- | Fred |- | Sarah |} {{col-end}}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:{{NumBlk|:| {{math|''R'' Γ· ''S'' {{=}} { ''t''[''a''<sub>1</sub>,...,''a''<sub>''n''</sub>] : ''t'' β ''R'' β§ β''s'' β ''S'' ( (''t''[''a''<sub>1</sub>,...,''a''<sub>''n''</sub>] βͺ ''s'') β ''R'') } }} |{{EquationRef|6}}}}where {''a''<sub>1</sub>,...,''a''<sub>''n''</sub>} is the set of attribute names unique to ''R'' and ''t''[''a''<sub>1</sub>,...,''a''<sub>''n''</sub>] 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 ''a''<sub>1</sub>,...,''a''<sub>''n''</sub> are the attribute names unique to ''R'' and ''b''<sub>1</sub>,...,''b''<sub>''m''</sub> 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'' := Ο<sub>''a''<sub>1</sub>,...,''a''<sub>''n''</sub></sub>(''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'' := Ο<sub>Student</sub>(''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) {{col-begin|width=auto; margin:0.5em auto}} {{col-break|gap=5em}} {| class="wikitable" |+ ''T'' |- ! Student !! Task |- | Fred || Database1 |- | Fred || Database2 |- | Eugene || Database1 |- | Eugene || Database2 |- | Sarah || Database1 |- | Sarah || Database2 |} {{col-end}} In the next step we subtract ''R'' from ''T'' [[relation (database)|relation]]: : ''U'' := ''T'' − ''R'' 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'' − Ο<sub>Student,Task</sub>(''R'') // This gives us a "what's missing" list. {{col-begin|width=auto; margin:0.5em auto}} {{col-break|gap=5em}} {| class="wikitable" |+ ''T'' |- ! Student !! Task |- | Fred || Database1 |- | Fred || Database2 |- | Eugene || Database1 |- | Eugene || Database2 |- | Sarah || Database1 |- | Sarah || Database2 |} {{col-break|gap=2em}} {| class="wikitable" |+ ''R'' a.k.a. ''Completed'' |- ! Student !! Task |- | Fred || Database1 |- | Fred || Database2 |- | Fred || Compiler1 |- | Eugene || Database1 |- | Eugene || Compiler1 |- | Sarah || Database1 |- | Sarah || Database2 |} {{col-break|gap=2em}} {| class="wikitable" |+ ''U'' |+ aka |+ ''T'' − ''R'' |+ aka |+ ''what's missing'' |- ! Student !! Task |- | Eugene || Database2 |} {{col-end}} 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'' := Ο<sub>''a''<sub>1</sub>,...,''a''<sub>''n''</sub></sub>(''U'') :: EG: Project ''U'' down to just the attribute(s) in question (Student) :: ''V'' := Ο<sub>Student</sub>(''U'') {{col-begin|width=auto; margin:0.5em auto}} {{col-break|gap=5em}} {| class="wikitable" |+ ''V'' |- ! Student |- | Eugene |} {{col-end}} So what remains to be done is take the projection of ''R'' on its unique attribute names and subtract those in ''V'': : ''W'' := Ο<sub>''a''<sub>1</sub>,...,''a''<sub>''n''</sub></sub>(''R'') − ''V'' :: EG: ''W'' := Ο<sub>Student</sub>(''R'') − ''V''. {{col-begin|width=auto; margin:0.5em auto}} {{col-break|gap=5em}} {| class="wikitable" |+ Ο<sub>Student</sub>(''R'') |- ! Student |- | Fred |- | Eugene |- | Sarah |} {{col-break|gap=2em}} {| class="wikitable" |+ ''V'' |- ! Student |- | Eugene |} {{col-break|gap=2em}} {| class="wikitable" |+ ''W'' |+ aka |+ {{math|(Ο<sub>Student</sub>(''R'') − ''V'')}} |+ aka |+ desired result |- ! Student |- | Fred |- | Sarah |} {{col-end}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)