0

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)?

philipxy
  • 14,867
  • 6
  • 39
  • 83
urig
  • 16,016
  • 26
  • 115
  • 184
  • 1
    I don't remember my notes exactly, but I don't think there is one. You have a JOIN in relational algebra, which is an X closed on the sides, but that's an operator and not a concept. – kirchner Feb 21 '18 at 12:16
  • 6
    It should be noted that SQL doesn't really talk about "relationship"s either. SQL has foreign keys that *reference* tables. The "relationship" terminology has come about, I believe, from people mis-applying the term from ERDs and getting confused by the fact that SQL claims to be "relational". People put 1 and 1 together and got cheese, but it seems impossible to stamp it out :-( – Damien_The_Unbeliever Feb 21 '18 at 12:41

2 Answers2

1

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.

philipxy
  • 14,867
  • 6
  • 39
  • 83
0

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.

Mark Wagoner
  • 1,729
  • 1
  • 13
  • 20
  • I agree: _if_ there's a cross-reference between tables in SQL (to avoid the word "relationship"), then that's tables within a database. As Relational Algebra is usually presented, it only talks about relations, not databases nor persistence nor update thereof. But see the writings of Date and Darwen for a fully worked-out model. – AntC Feb 21 '18 at 16:41