I remember being taught to never create a loop when connecting tables in sql. In fact, using Business Objects, he even tells me if there are cycles in the circuit that I defined in the Universe.
I tried searching the Internet for this statement, but I could not find the link.
Why is this dangerous?
Edit: maybe I was too succinto.
My question was not about a loop designed as "FOR LOOP" or similar. I talked about something like this WHERE clause in a SELECT statement:
WHERE TABLE1.foo = TABLE2.foo AND TABLE2.bar = TABLE3.bar AND TABLE3.baz = TABLE1.baz
if you draw a relation, you will see a “loop” in the connection. Is it dangerous in terms of correctness and / or performance?
Thanks to everyone.
Edit 2: added an example.
I just came up with an example, maybe this is not the best, but I think it will help to understand.
------------ ----------------- ---------------------- - DELIVERY - - DELIVERY_DATE - - DELIVERY_DETAILS - ------------ ----------------- ---------------------- - id - <--- - id - <----- date_id - - company - |----- delivery_id - - product - - year - - date - - quantity - - number - ----------------- - datetime_of_event - - customer - ---------------------- - ---------- 1 <-----> N 1 <----> N
- In the DELIVERY table, each delivery appears only once.
- At DELIVERY_TABLE, we have a list of each date on which delivery was processed. Thus, delivery can be prepared in a few days.
- In the last table, we describe each delivery in detail. So, in this table we track every event related to the preparation of the delivery.
So, the capacities are 1: N for each pair of tables.
The connection is very simple:
DELIVERY.id = DELIVERY_DATE.delivery_id AND DELIVERY_DATE.id = DELIVERY_DETAILS.date_id
Now suppose I want to join another table where I have other information for delivery on a specific date. Let him determine it:
Now the connection should be:
DELIVERY.id = DELIVERY_DATE.delivery_id AND EMPLOYEE.company = DELIVERY.company AND EMPLOYEE.year = DELIVERY.year AND EMPLOYEE.number = DELIVERY.number AND EMPLOYEE.date = DELIVERY_DATE.date
To summarize, I conclude that EMPLOYEE will join both DELIVERY and DELIVERY_DATE, having a loop in the join.
Should I rewrite it this way?
EMPLOYEE.company = DELIVERY.company AND EMPLOYEE.year = DELIVERY.year AND EMPLOYEE.number = DELIVERY.number AND EMPLOYEE.date IN (SELECT date FROM DELIVERY_DATE d WHERE d.delivery_id = DELIVERY.id)
Edit 3: finally found the link
As usual, when you refuse to search for a link, you will find it.
So this article explains everything. This is related to business objects, but the content is shared.
Thank you all for your time.