Chapter 2 - Relational Algebra Flashcards
What is relational algebra?
It is a procedural language used for performing operations on relational DB.
It serves as the foundational, low-level operations that are used by Database Management Systems (DBMSs) to manipulate data
Relational Algebra vs SQL?
Relational Algebra is procedural, meaning it specifies how operations should be carried out step by step. Users define a series of operations to be performed on data.
SQL, on the other hand, is declarative. In SQL, users specify what data they want to retrieve or manipulate and the DBMS determines how to execute the request.
Relational algebra is basically more low level and SQL more high level
What does it mean when we say relational algebra forms the basis for the implementation of DBMSs.
It provides the fundamental operations that a DBMS needs to perform tasks like querying, inserting, updating and deleting data.
Click to see procedural and declarative difference
Procedure language
Specify what to get and how
to get
E.g.
do while(isspace(s)) s++;
while(d++ = *s++)
Declarative language
Specify what to get
E.g.
out_str = re.sub (r’^\s+’, ‘ ‘,
input_string
What can relational algebra operators be divided into? At a higher level.
It can be divided into basic operators and extended/derived operators
What can basic operators be divided into?
Unary operators and Binary operators
What is a unary operator
Unary operators are operators that operate on a SINGLE OPERAND.
These operators are often used for tasks such as NEGATION, INCREMENTING, DECREMENTING or CHANGING SIGN OF A SINGLE VALUE.
Example Unary operators in programming language include the negation operator -x, the logical NOT operator !x and the increment operator x++
What is a binary operator?
Binary operators are operators that operate on two operands. They require two values or variables to perform an operation.
They are commonly used for arithmetic operations (addition, subtraction, multiplication, division), logical comparisons (equal to, not equal to, greater than, less than) and other operations that involve two values.
Examples of binary operators include addition (x+y), equality comparison (x==y), and logical AND (x && y).
What falls under Unary operators out of the Fundamental Operators?
- Projection (π)
- Selection operator (σ)
- Rename operator (p)
How is the select operator represented?
The Select operator in relational algebra is represented as 𝜎𝑃(𝑟), where:
𝑟 represents one relation (table).
𝑃 represents one or many attributes of relation 𝑟, often referred to as predicates.
What is P
P stands for Predicate.
They are conditions or expressions that can involve logical operators like ‘and’ (∧), ‘or’ (∨), and ‘not’ (¬).
Comparison operators like >=, >, =, !=, <, and <= can also be used in predicates.
Click to see how a select statement is written in relational algebra
𝜎(Gender = ‘Female’ ∧ Age > 20)(Students)
In this predicate:
“Gender = ‘Female’” is a condition that checks if the student’s gender is female.
“Age > 20” is a condition that checks if the student’s age is greater than 20.
The ‘∧’ (logical AND) operator is used to combine these conditions, meaning both conditions must be true for a row to be selected.
How is the project operator represented? and how does this operator work?
Notation: π𝑎,𝑏,…(𝑟)
r represents one relation.
a,b represents the attributes (columns) that you want to select from the relation.
Project operator is a column-wise operation that returns only specified columns.
Is it possible during project operation to end up with return of fewer tuples?
It is possible for the Project operator to return fewer tuples (rows) than the original relation r. This happens when there are duplicate values in the selected columns.
Duplicate values are removed in the result, resulting in a reduced number of tuples
What would the project operator look like in SQL?
SELECT a, b
FROM r