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 database
(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!
==Relational operations== {{Main|Relational algebra}} Queries made against the relational database, and the derived [[relvars]] in the database are expressed in a [[relational calculus]] or a [[relational algebra]]. In his original relational algebra, Codd introduced eight relational operators in two groups of four operators each. The first four operators were based on the traditional mathematical [[Set theory|set operations]]: * The [[Union (set theory)|union]] operator (Ο ) combines the tuples of two [[relation (database)|relations]] and removes all duplicate tuples from the result. The relational union operator is equivalent to the [[Union (SQL)|SQL UNION]] operator. * The [[Intersection (set theory)|intersection]] operator (β©) produces the set of tuples that two relations share in common. Intersection is implemented in SQL in the form of the [[Intersect (SQL)|INTERSECT]] operator. * The [[Complement (set theory)|set difference]] operator (-) acts on two relations and produces the set of tuples from the first relation that do not exist in the second relation. Difference is implemented in SQL in the form of the [[Except (SQL)|EXCEPT]] or MINUS operator. * The [[cartesian product]] (X) of two relations is a join that is not restricted by any criteria, resulting in every tuple of the first relation being matched with every tuple of the second relation. The cartesian product is implemented in SQL as the [[Cross join]] operator. The remaining operators proposed by Codd involve special operations specific to relational databases: * The selection, or restriction, operation (Ο) retrieves tuples from a relation, limiting the results to only those that meet a specific criterion, i.e. a [[subset]] in terms of set theory. The SQL equivalent of selection is the [[Select (SQL)|SELECT]] query statement with a WHERE clause. * The [[Projection (relational algebra)|projection operation]] (Ο) extracts only the specified attributes from a tuple or set of tuples. * The join operation defined for relational databases is often referred to as a natural join (β). In this type of join, two relations are connected by their common attributes. MySQL's approximation of a natural join is the [[Inner join]] operator. In SQL, an INNER JOIN prevents a cartesian product from occurring when there are two tables in a query. For each table added to a SQL Query, one additional INNER JOIN is added to prevent a cartesian product. Thus, for N tables in an SQL query, there must be Nβ1 INNER JOINS to prevent a cartesian product. * The [[Relational algebra#Division|relational division]] (Γ·) operation is a slightly more complex operation and essentially involves using the tuples of one relation (the dividend) to partition a second relation (the divisor). The relational division operator is effectively the opposite of the cartesian product operator (hence the name). Other operators have been introduced or proposed since Codd's introduction of the original eight including relational comparison operators and extensions that offer support for nesting and hierarchical data, among others.
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)