0

When talking about relational databases, it seems that most people refer to the primary and foreign key 'relations' as the reason for the 'relational database' terminology.

This is causing me considerable confusion because the textbook linked below states explicitly "A common misconception is that the name "relational" has to do with relationships between tables (that is, foreign keys). Actually, the true source for the model's name is the mathematical concept relation. A relation in the relational model is what SQL calls a table."

http://www.valorebooks.com/textbooks/training-kit-exam-70-461-querying-microsoft-sql-server-2012-microsoft-press-training-kit-1st-edition/9780735666054#default=buy&utm_source=Froogle&utm_medium=referral&utm_campaign=Froogle&date=11/12/15

Furthermore the next source explicitly refers to the tables as the relations and not the primary/foreign keys. https://docs.oracle.com/javase/tutorial/jdbc/overview/database.html

However it seems common knowledge almost anywhere else I look or read that the primary and foreign keys are the relations.

Does anyone have a reason for the inconsistency?

  • "Common knowledge" - it's tables and their relationships. Confusion is yours; different sources choose to emphasize one or the other. What you call an inconsistency doesn't seem to prevent anybody else from understanding and using relational databases and SQL effectively. – duffymo Nov 13 '15 at 15:40
  • "*it seems that most people refer to the primary and foreign key 'relations' as the reason for the 'relational database' terminology*" - I don't think that is true. I have never met anyone that assumed that - it has always been clear that this stems from "relational algebra". And the [Postgres manual](http://www.postgresql.org/docs/current/static/tutorial-concepts.html) also clearly states that: "* Relation is essentially a mathematical term for table*" –  Nov 14 '15 at 14:57
  • See [this answer](http://stackoverflow.com/questions/27268711/what-is-the-difference-between-an-entity-relationship-model-and-a-relational-mod/27272088?s=4|0.0646#27272088) and its question. – philipxy Dec 05 '15 at 03:17

1 Answers1

3

Foreign key constraints are a kind of relation - a subset relation - but these aren't the relations from which the model derives its name. Rather, the relations of the relational model refer to finitary relations. Ted Codd wrote in his 1970 paper A Relational Model of Data for Large Shared Data Banks that "The term relation is used here in its accepted mathematical sense. Given sets S1, S2, ... Sn (not necessarily distinct), R is a relation on these n sets if it is a set of n-tuples each of which has its first element from S1, its second element from S2, and so on." Thus, he was describing a structure which can be represented by a table, if we follow some rules like ignoring duplicate rows and the order of rows (it's a set, after all).

Another common misunderstanding is that foreign key constraints represent relationships between entities. They don't. Relationships are represented as sets/tables of rows of associated values. The keys of two or more entities will be recorded together in a row, whether it's in an "entity table" or a "relationship table". Foreign key constraints only enforce integrity, they don't link entities or tables. Tables can be joined on any predicate function, foreign key constraints play no role here.

Most people learn database concepts from blogs, tutorials and answers ranked by popularity. Most people have never read a decent database book, let alone papers by the inventors and students of the relational model of data. Most programmers and corporations want to get the product released and have little time or appreciation for logic, theory and philosophy. It's an inherently complicated field - see Bill Kent's book Data and Reality for an exploration of this complexity. Thus, most of what you'll find on the internet are half-truths at best as people try to make sense of a difficult topic.

People are familiar with records and pointers, due to their prevalence in mainstream programming languages, and they certainly look and sound a lot like entities and relationships. If entities are represented by tables/records, attributes by fields/columns, then 1-to-1 / 1-to-many relationships between entities must be an association between records/tables, right? It's a simple idea, and that makes it difficult to correct. The popularity of object/relational mapping and object-oriented domain models derive from this simple idea (and from well-spoken and sociable authors, unlike the surly attitudes of some relational proponents) but also further entrenches it.

Peter Chen (author of The Entity-Relationship Model - Toward a Unified View of Data made some effort to be rigorous, distinguishing "entity relations" and "relationship relations". In his view, entities were real-world concepts which were represented in a database as values, and described via association of values in rows. Relationships between entities were similarly represented by association of values in rows. The E-R model's distinction between relationships and attributes is somewhat redundant (attributes are just binary relationships) and there's little benefit in distinguishing entity tuples from relationship tuples. In fact, I believe it serves to reinforce the confusion. It's superficial similarity to the older network model helped its adoption but also served to maintain the latter, as developers adopted new terminology while maintaining old practices.

Object-role modeling (aka NIAM, by Sjir Nijssen and Terry Halpin) does away with attributes and focuses on domains, roles and relations. It's more elegant than E-R and much closer to a true relational model, but its strengths (logical, comprehensive, move away from the network model) is also its weaknesses (learning curve, more complicated diagrams, less amenable as a vehicle for familiar techniques).

Ted Codd remarked in the paper mentioned above that "The network model, on the other hand, has spawned a number of confusions, not the least of which is mistaking the derivation of connections for the derivation of relations." This is as true today as it was then. The relational model which he described has since been built on by many others, including Chris Date whose book An Introduction to Database Systems is one of the most comprehensive sources on the topic.

I'm naming all these authors because one more opinion on either side isn't going to clear up your confusion. Rather, go to the sources and study them for yourself. Yes, it's hard work, but your efforts will be repaid in the quality of understanding you'll gain.

reaanb
  • 9,806
  • 2
  • 23
  • 37
  • "[X][XLIST] is a FK to [Y][YLIST] is a relation(ship) on base tables and column lists. A FK is only an *instance of* it. Eg "T (A,B) is a a FK to U (B,C)". Aka a *fact*. (That a certain projection of a certain table suitably renamed is a relational subset of a certain projection of another table.) The fact that certain things participate in a certain relation(ship); that they are related in that way. So calling a FK a "relation(ship)" not only gets the relational sense of the term wrong but misuses it for "fact that two tables & column lists participate in the relation(ship) called 'FK' ". – philipxy Dec 03 '15 at 18:32
  • @philipxy I'm always happy to get your feedback, but not sure if you're agreeing with me or correcting me? I don't refer to foreign keys as relation(ship)s in data since base tables and column lists aren't relatable domains in the data (they are in the metadata/schema). – reaanb Dec 03 '15 at 23:16
  • 1
    Great answer. I was reacting only to "Relationships are represented in rows as associated values". What is clearer is "Relationships are represented as sets/tables of rows of associated values" and "Relationship instances [ie instances of entities being related in a given way] are represented as rows of associated values". (And I can't quite parse your "as".) Then I was inspired to add to your FKs-are-not-relationships by noting that a particular FK is an instance of the (metadata) relation(ship) "... is a FK to ...". – philipxy Dec 04 '15 at 02:22
  • Thanks for the explanation. I revised my answer a bit, these comments are fine addenda for future readers. – reaanb Dec 04 '15 at 09:46