Questions tagged [relational-algebra]

Relational Algebra is an offshoot of first-order logic and of the algebra of sets that deals with relations (sets of tuples). In Computer Science, Relational Algebra is commonly used when dealing with databases. Operators in Relational Algebra use relations as operands and produce a relation as a result.

Relational Algebra provides a formal system for working with relations. In the context of databases, it can be thought of as a more formal way of constructing queries on relations.

Relational Algebra supports the following operations:

  • Set operators: Union (∪), Difference (-), Intersection (∩) (relations must be union compatible i.e., the number of attributes and their domains must match).
  • Projection (π): This is a unary operation that lets you select a specific subset of attributes (columns) from a relation.
  • Selection (σ): This is a unary operation such that the expression σφ(R) lets you select a subset of relations from the relation R that satisfy a certain propsition φ. This proposition is expressed using logical operators where the atoms are of the form aθb where a and b refer to attributes and θ refers to a binary operation in the set {<, <=, =, >=, >}
  • Rename (ρ): This is a unary operation of the form ρa / b(R) where the result is identical to R except that the attribute a has been renamed to b. This operator can be used to rename attributes or the relation itself.
  • Natural join (⋈): Natural joins (⋈) is a binary operator that is written as (R⋈S) where R and S are relations. The result of the operation is the set of all combinations of tuples in R and S that have equal values on their common attribute names.
  • Theta Join (⋈aθb): A theta join is a conditional join where the result of the operation is the set of all combinations of tuples in R and S that satisfy the condition specified. Using the already-defined operators a theta join can be expressed as R⋈φS = σφ(R × S).
  • Division (÷): Division is a binary operation that is written as R ÷ S. Assuming R is defined as R(a, b) and S is defined as S(b), the result of R ÷ S is the relation T(a) where a tuple <a> is only in T if there are tuples in R of the form <a, b> such that an a in R is associated with every value of b in S.

When teaching databases, Relational Algebra is used as a formal foundation before the introduction of SQL (Structured Query Language). SQL is similar to Relational Algebra except that it supports a few extended operators. A few of the differences can be summed up as follows:

  • Relational Algebra is procedural whereas SQL is declarative
  • Relational Algebra deals with sets of tuples whereas SQL deals with bags.
  • Standard Relational Algebra does not support aggregate operators like summing.
  • Standard Relational Algebra does not support grouping.
  • Standard Relational Algebra does not support ordering or sorting.
  • Standard Relational Algebra does not support pattern-matching operators.

External links:

577 questions
-3
votes
2 answers

relational algebra of the query

Consider the following relational database schemes: COURSES (Cno,name) PRE-REQ(Cno, pre-Cno) COMPLETED (student_no, Cno) COURSES gives the number and name of all the available courses. PRE-REQ gives the information about which courses are…
-3
votes
1 answer

database relational algebra , sql query

5.Consider the following library schema Books (book_no,title,authors,publisher) Borrower(borrower_id, name, DOB, job) Borrowed(borrower_id,book_no,date) Write the following queries in relational algebra a. Find the name and the borrower_id of…
raghad
  • 21
  • 1
  • 5
-3
votes
1 answer

Complex Relational Algebra?

We have 3-Relation: Students(sid, sname) Courses(cid, cname, dept) take(sid, cid, grade) Who Can Describe these relational algebra for me? Is equivalent to second one:
user5920466
-3
votes
1 answer

Strategies for understanding complicated SQL SELECT statements

I've been trying to get my head round some very tricky SQL queries in MySQL (can range from nested queries, correlated sub queries, group concatenation, temporary tables and self joins). These are often very large and very complicated. Recently…
LeDoc
  • 935
  • 2
  • 12
  • 24
-3
votes
1 answer

Relational algebra ONLY & EVERYWHERE

Here is a simple database /* Delete the tables if they already exist */ drop table if exists Person; drop table if exists Frequents; drop table if exists Eats; drop table if exists Serves; /* Create the schema for our tables */ create table…
John Rock
  • 133
  • 1
  • 12
-5
votes
1 answer

Why are these two queries different?

Display the details of the employees who have subscribed for Football and Chess but not for Tennis. SELECT * FROM employee WHERE empid IN (SELECT empid FROM subscription WHERE facid IN (SELECT facid …
Pop Stack
  • 926
  • 4
  • 19
  • 27
-5
votes
1 answer

Can I do this relational algebra sentence in SQL?

π LOC, DEPTNO(DEPT) – πDEPTNO (σLOC-‘DALLAS’(DEPT))
yosiam
  • 1
  • 1
1 2 3
38
39