Serves you right for using wiki as a reference. The content is populated by anyone and changed by everyone. It has no sense of authority. And the ever-changing opinions of the uneducated masses is not "authority".
There are errors in the diagram as well. It is not in 3NF and it does not prevent OrderItems from being Invoiced more than once. It is a naïve model.
> For me the essential aspect seems to be the rule (which doesn't even
> seem to be mentioned in the english-language Wikipedia article) that the
> dependency graph of all entities must not contain directed circles,
> i.e. there must be no "hen and egg"-type dependencies between entities.
Yes, that is a very good rule to have. I have used that as a rule "Thou shalt not have circular references" since 1984. All the good Rdbs I have ever had to audit have had that rule. But it is a rule, a design principle, like "look left *and* right before crosiing the road". Addition of that rule to a data model or a modelling notation does not form a new modelling notation. Yes, it is more structured than an ER model without it, but it does not warrant a new name. My databases have several such rules (this is just one), for quality and performance purposes, I still call them Relational databases plus published standards, not "structured relational database". People expect that normal human being can cross the road without killing themselves, we do not need "structured human".
SAP is not exactly famous for modelling databases, and their dbms were horrible before they acquired Sybase.
IDEF1X is the established standard for modelling Relational databases, and is the only one that (a) Codd was involved in and (b) actually implements the RM (it does not prevent non-RM constructs, unfortunately). The notation is full and complete. One addition, most people use IEEE notation instead, for the relationships, because they are more explicit and everyone understands them.
Notice, in the diagram, it refers to "Customers without any orders are legal because they are independent Entities." But it fails to define "Independent" or "Dependent". Those are formal terms in IDEF1X. So even those authors have had to evaluate the model in those terms, and make the determination, even though they do not credit Codd or Chen or brown or IDEF1X.
Yet another diagrammatic notation is plain stupid.
> Now what do theorists think:
>
> Is it perfectly evident that this requirement must be enforced, since a
> model with cyclic dependencies is plain "spaghetti", maybe even
> violating some normal form?
It violates common sense. One knows that something is wrong; that it will cause problems; one does not need a theorist to come up with a rule or a hilarious "mathematical definition" to prove that the common sense God gave us is a Good Thing. One does not need a rule to prevent one from doing silly things.
> Or does it depend on
> the specific case, since there may be situations where it can't be
> achieved, and a model that violates this rule can be perfectly valid?
A rule is a rule is a rule. There is never a circumstance where breaking the rule is acceptable. "I crossed the road without looking left because I thought I was in Africa".
There is no such thing as a valid database that has an invalid article in it. The fact that it has an invalid article (here, a circular reference), makes it invalid. I have audited close to a hundred databases, and corrected problems therein. Whenever someone has implemented a circular reference, that *always* causes massive problems, and the customer *always* asks me to address that problem first (other problems may be hidden, but this one is a bleeding sore).
Correcting it is always straight-forward. The correction in the db (changing the constraint definitions) is easy. The correction in the mindset of the people who implemented it, takes more work.
The example in the wiki article is not a valid one for the chicken-and-egg problem, or resolution thereof, so let us use a valid one. In a banking system, one rule states that in order to open an account, the new customer must deposit a minimum of $10. Another rule states that every account must have a customer. Now, if you have lost your common sense, or you think that every business requirement must be implemented as stated (which makes you a clerk, not an technician), then will see this as a dilemma, and struggle with it for weeks. The looneys on TTM argued about it for a year.
But if you have been to Mass recently, and you have not excised the gifts that God gave you, you will realise this is not a banking problem or a clerical problem or a big problem. It is a database, everything is integrated with everything else. It is not two separate rules taken in isolation. Just choose an Order: identify and establish the Customer first; then create an account; then deposit $10. It is the same resolution that we have used to prevent (and to resolve) deadlocks since the 1960s. Choose the constraints carefully, and they have only one direction, never circular.
> I've noted that in practice, graphical modelling tools seem to be prone
> to making users produce models where this rule is violated. There
> don't seem to be modeling tools that would allow checking for such
> dependencies resp. preventing them.
Modelling tools are not a replacement for brains. Or for understanding the task of modelling. Some are better than others, and prevent Bad Things in general, but even that can be easily circumvented. The best they can do is warn you of what looks like a problem. ERwin (the tool, not the correspondent on this channel) is the best by far, it implements IDEF1X, ie. the RM. But even that can be circumvented or ignored by someone who is clueless.
> > Using the SERM example on the wikipedia page, the graph says every
> > order has N order items, and every order item has 1 order. Although
> > drawn as just one line, that line states two rules, mutually
> > dependent: a cycle. (Try using DRI to enforce them.)
>
> And just two (mutually co-dependent) constraints wouldn't be enough
> to correctly implement the semantics, as far as I understand. But
> database design books don't seem to explain it either. At least those
> that I have access to. Or am I just blind?
You are not blind, but you are blinded by the waffle on this noisy channel. Evidently James does not know much about Relational databases or SQL.
• that one line is one relationship
• it is defined by one (and only one) constraint
ALTER TABLE OrderItem (not Order)
CONSTRAINT xyz FOREIGN KEY (Order_PK)
REFERENCES Order (Order_PK)
• the relationship is identified by the Verb Phrase or Business Rule:
Each Order has n OrderItems.
• it is not two rules
• it is the same one , reading the relationship definition line in the mode stated in reverse (reverse the verb phrase or business rule):
Each OrderItem has one and only one Order
There is nothing mutually dependent or co-dependent about it. There is only one direction in the constraint, in any constraint. The fact that one does not add (note I did not state INSERT) an Order without adding any OrderItems, is a matter of the transaction. As long as you have platform that supports transactions, and SQL compliance requires ACID transactions. So simply make sure that the transaction code does not add a Order without at least one OrderItem.
Now here is where people who have been trained to be stupid (by reading books written by subverters or taking lessons in fragmented thinking), to run into each other like circus clowns, see an opportunity to exercise the training they acquired at great expense, that they are so attached to. They will not see that the database is an integrated unit, and that the transactions as integrated into it. No, they will get hung up at the mis-conceptual or ill-logical level, and demand a constraint to enforce the non-business rule that "every Order must have at least one OrderItem". So even where there is no circular reference, they will introduce the non-logic that demands one. And then implement the stupid thing. That is why I stated, the problem is not in the database, it is in the mindset.
> This issue (it's "just" a 1:n relationship with n>0, right?)
It is.
> must be
> as old as the relational database model itself (fourty years now?).
It is. Resolved forty years ago as well.
> I've tried to google for the relevant terms, and couldn't find a
> documented example for a correct, tested solution. Or is it just that
> you need to know *the* terms to search for?
You are expecting technically valid answers from a ever-changing pile of excreta produced by uneducated masses ?
> Does someone in this group know of a book (or an online document) that
> shows how to *correctly* implement such things? And maybe one that also
> gets other things (that I haven't stumbled over yet) *right*?
Read only Codd.
Throw out anything written by anyone else, especially if they claim to champion or explain the RM.
> Something
> like "database design caveats that most textbooks conveniently ignore"?
I will post when I write it ;}
Here's a chapter that you may be interested in, and Introduction to IDEF1X. It does handle a few caveats, but it is not a detailed how-to doc:
http://www.softwaregems.com.au/Documents/Documentary%20Examples/IDEF1X%20Introduction.pdf
>> Look for "deferred constraint checking". Oracle and PostgreSQL support that.
Interesting. The high end vendors (DB2 and Sybase) don't have it. There is a reason for that, it is well-known that both modellers and developers at the high end have the full three digits in the IQ department. They have been implementing Relational databases with a full set of Constraints for decades, such as ensuring that Orders have at least one OrderItem, but have never needed a constraint to enforce that particular database integrity. They understand the content of my post. PostgreNonSQL doesn't have SQL transactions.
But at the low end, where the clowns are very attached to running into each other, over and over again:
• ensure they never hear about the "no circular reference" rule, or understand the problem is outside the database
• give them a platform that allows circular references, and has a "method" of allegedly resolving it. Don't worry dear, everything will be alright in the end.
• good for justifying machines that need twice the CPU power
• then wail about the competition not having said absurd feature. Good for making sales by box-checkers.
First train them to be stupid, then sell them machines and software that only stupid people need. That is the theory. Which is why you need engineers, not theorists. Unfortunately few of us write books.
Cheers
Derek