It seems strange to me that, when I've defined a foreign key, the engine cannot use this information to automatically figure out the correct JOIN expressions, but instead requires me to re-type the same clauses. Are there any databases, perhaps some kind of research project, that will inspect the existing foreign keys?
3 Answers
It would be really cool if I could write this
from calendar join table1
and the dbms would know that it needs to evaluate this.
from calendar
left join table1 on (work_date between (cal_date - 13) and cal_date)
Really cool. But not every join is an equi-join.
FWIW, NATURAL JOIN is in the SQL standard. But I'm pretty sure I haven't used it in the last 25 years.
If you find yourself writing the same join clauses over and over, maybe you just need more views.
- 10,766
- 1
- 36
- 43
I'm not aware of any that use foreign keys (and that would can be messy if you have more than one foreign key back to the same table)
There are auto-complete utils for your editor of choice to auto-suggest appropriate join statements if typing is the concern. RedGate's SQL Prompt for handling SQL Server in SSMS & Visual Studio. I believe Quest's TOAD will handle Oracle and some of the other more popular RDMSs.
- 5,013
- 1
- 24
- 28
-
No real "concern", just wondering if this is something anyone is looking into addressing. – TML Jan 11 '11 at 00:57
-
@TML I doubt anyone is worried about this as this is really in the domain of application logic to my understanding (where application logic is the things that don't pertain to running a database server, the things we get paid to do) – jcolebrand Jan 11 '11 at 04:16
natural joinhas never been the default". Incidentally, Tom Kyte is surely right when he callsnatural joina bug waiting to happen – Jack Douglas May 02 '11 at 12:08