News for hackers. Stuff that matters.
Re:We do not use foreign keys (2016) by SkyPuncher on Friday November 08, 2019 @05:14PM (#21487455)
> It violates the rules of how the data relates

You're missing an important point, it violates a certain set of rules of how the data relates. That certain set of rules typically makes it easier to write most general data applications.

If your rules define a foreign key as optional, you can easily engineer an application around it.

Great examples include NoSQL and Ruby duck-typing. In both cases, you infer actions based on the data structure, rather than making explicit assumptions.

Re:We do not use foreign keys (2016) by Aeolun on Friday November 08, 2019 @05:59PM (#21487810)
The whole fact that you made a foreign key implies that that is now a rule of your database. If anything is in that column that does not adhere to the foreign key, that means your database is corrupted.
Re:We do not use foreign keys (2016) by lugg on Friday November 08, 2019 @06:31PM (#21488062)
Yes, and what if you don't make a foreign key?
Re:We do not use foreign keys (2016) by spookthesunset on Friday November 08, 2019 @06:49PM (#21488204)
Then you have an implicit rule that is enforced by a hope and a prayer that some junior dev never makes a mistake, your senior engineers are clairvoyant and understand every single aspect of your systems 100% with zero off-days, your code review process catches every single possible edge case (especially the edge cases that you never knew existed), your QA process is 100% and never makes mistakes, your servers never crash in ways that leave things in an inconsistent state, etc.

Or you could, you know, simply add a foreign key constraint and never, ever, ever have corrupt table relations.

Why people fight their tools is beyond me. There is almost zero reason to defend not using foreign keys.

Re:We do not use foreign keys (2016) by hootbootscoot on Saturday November 09, 2019 @04:00PM (#21494324)
or you never wanted it in the first place.

i suggest being open to the concept that other perfectly capable humans may, in fact, design systems with different underpinning assumptions than those you appear to presuppose always must apply to everyone and everything.

It's important to remove the DBA or Developer hat and realize that you are working together on a singular system (or maybe it's even the same person, etc.)

"corruption" implies that the desired results have not been achieved, that essential data has been lost or compromised, and this clearly is not the case with such a deliberate design decision. one should be prepared to accept this possibility in order to not be merely a fanatic and unreasonable.

Re:We do not use foreign keys (2016) by jerzyt on Friday November 08, 2019 @07:42PM (#21488581)
That's exactly my experience and viewpoint.
Re:We do not use foreign keys (2016) by js4ever on Saturday November 09, 2019 @05:26AM (#21490680)
Mine is exactly the opposite, most use cases I'm exposed to do not require FK at all, so I simply never use them.