Relational algebra - Theoretical Flashcards
Learn the five fundamental database operations and how they work
What is relational algebra?
It is a formal language that created to formally describe relational databases
What is a relation?
A table
What is a closure in relational algebra?
It is a nested query (subquery) which output is used in the outer query.
e.g: SELECT * FROM Employees WHERE DName = (SELECT Dname From Departments WHERE Dname = "Research")
How many operations are there in relational algebra?
Originally it included 8 but more have been added since..
What is a unary operation?
An operation that only involves one single relation (1 table)
How many fundamental operations are there in relational algebra?
Five;
- selection
- projection
- Cartesian product
- union
- minus.
What are the additional operations besides the fundamental ones in relational algebra??
Join
intersection
Division operations
What is a binary operation?
an operation that do work on two relations (2 tables) and results in a single table (it shows the result in a new table).
What is the selection operation?
Unary operation (works on a single table), it defines a new relation (table) with all the tuples (rows) that is selected (satisfy condition)
What is the projection operation?
Unary operation that outputs a new relation that contains all the columns of given attributes.
e.g. all names that exist in the table, by selecting all names and phonenumbers.
What is the union operation?
Binary operation(two relations) Outputs one relation that contains all the tuples of the two relations without duplications
What are the requirements of the union operation?
The schemas must match; same number of attributes and the corresponding attributes has the same domain (but naming is irrelevant)
What is the minus operation?
Binary operation that defines a relation consisting of tuples that are in one but not the other.. So rows that only exist in one of the tables
opposite of intersection
What is the intersection operation?
binary operation that results in a relation that consist of only the tuples that exist in both realtions.
Rename operation
unary operation that gives new names to a relation or attributes.
Cartesian product operation
binary operation that defines a relation, that consists of the concatenation of every tuple of both relations. null can appear
What are joins
binary operations that outputs one table with data from both tables.
What types of joins exist?
We distinguish between Inner- and outer-joins.
Inner Joins: Theta, Natural, EQUI
Outer Join: Left, Right, Full
What is considered as the default join operation?
EQUI / INNER JOIN
What is an EQUI / INNER JOIN
INNER JOIN that is comparator-based; it uses ‘=’ comparisons to do joins.
Here is an example of an equi-join:
SELECT * FROM TableName1, TableName2 WHERE TableName1.ColumnName = TableName2.ColumnName; -- OR SELECT * FROM TableName1 JOIN TableName2 ON TableName1.ColumnName = TableName2.ColumnName;
If we do joins with another operator than ‘=’ is it then an equi-join?
No, that is a theta join.
a theta join becomes an equi join by using only the = operator
What is a theta join
It is also an INNER JOIN that allows you to join based on other operators than = like: , ≥, ≠
How can you choose between using theta or equi join?
If your theta join only uses = DBMS will make use of equi join