If I understand correctly, the Relational Algebra equivalent of a SQL table
is a relation
.
What is the equivalent term in Relational Algebra of a SQL relationship
(i.e. between two tables)?
If I understand correctly, the Relational Algebra equivalent of a SQL table
is a relation
.
What is the equivalent term in Relational Algebra of a SQL relationship
(i.e. between two tables)?
A "relationship" [sic] between two tables or relations is a notion from pseudo-ERM (Entity-Relationship Model) information modeling methods, products & presentations that call themselves ERM but aren't because they misunderstand, misuse & misrepresent the ERM & RM (Relational Model). It isn't a term from SQL. It corresponds to a FK (foreign key) in the RM.
(In the ERM & RM a "relationship" is an "association" is a "relation" in the sense of a truth-valued function. As represented by a RM "relation" in the sense of a collection of tuples of entities/values that participate together.)
A SQL FK corresponds to what we could reasonably call a foreign superkey in the RM. Does an empty SQL table have a superkey? Does every SQL table?
(The ERM & SQL also misunderstand, misuse & misrepresent the RM. What is the difference between an entity relationship model and a relational model?)
A RA (relational algebra) is a system of values & operators on relations & maybe other types. A language whose expressions are essentially nested RA operator calls is often also sloppily called a RA. A relation (value or variable) FK is a set or list of attributes whose subtuple values are constrained to appear elsewhere. A FK constraint says that subtuple values for a given set or list of attributes in a given named relation also appears under given attributes of a second given named relation. (Such a constraint is also sloppily called a FK.) Since a FK constraint is a statement about relation values and not a relation value, it isn't expressible directly in terms of relation values & operators. It could be in a particular RA-style query language that lets you write boolean-valued expressions.
One RM notion of FK as set is that {r, ...} is a FK in R referencing CK {r, ...} in S iff/when project r, ... (R)
is a restriction of project r,... (S)
. One notion of FK as list is that (r, ...) is a FK in R referencing (s, ...) in S iff/when {s, ...} is a CK of S and rename r\s, ... (project r, ... (R))
is a restriction of project s,... (S)
.
Nevertheless it is straightforward to express constraints while limiting ourselves to relation names & nested RA calls. We express whether a constraint holds on given named relations via a query that has some agreed-upon property iff/when the constraint holds. One such convention is to give a query that returns an empty relation iff/when its named relations satisfy the constraint. The simplest convention is a query that returns a relation with no columns (of which there are two, the one with a tuple & the one without) that has a tuple iff/when the constraint is satisfied.
I don't believe there is one. The concept of related sets isn't part of set theory. You only have sets and the operators that act upon them.