Foreign keys also let the query optimizer make better query plans. This is actually a bigger deal than most people think, the query optimizer can rewrite to semi joins or even eliminate joins completely if the optimizer has better guarantees about referential integrity.
Ask HN: Do you use foreign keys in relational databases?
141–150 of 251 posts
Re: Ask HN: Do you use foreign keys in relational databases?
#142Re: Ask HN: Do you use foreign keys in relational databases?
#143In other words, the world is full of idiots; and any time I start forgetting about it, I read something like your post and I get a wake-up call.
What does R stand for in RDBMS is you don't use foreign keys and joins?
Please, keep using your FKs, stay safe and don't mingle too much with idiots.
Re: Ask HN: Do you use foreign keys in relational databases?
#144Earlier quoted context omitted.
> Much better than ORMs I recently migrated to EntityFramework Core (from the non-core version) and I’m actually impressed. Most SQL is pretty much what I’d write by hand. Now granted, if there are complex joins, subqueries and stuff, I don’t even try wrangling the ORM to somehow give me that output, but still. I feel more comfortable just using EF than I used to.
My main problem with Entity Framework is the magic underneath. Like simple operation x = Ef.Find(xid) x.Name = "something" y = Ef.Find(xid) what is y.Name ? Even though you didn't save anything to the database yet ? And the second Find didn't actually refresh from the database ? Oh and the random bugs where people improperly include related entities but it somehow ends up working because they are automatically added…
Re: Ask HN: Do you use foreign keys in relational databases?
#145I agree with your colleague, and I insist on pushing my car everywhere because I fear gas as it is flammable. In other words, the world is full of idiots; and any time I start forgetting about it, I read something like your post and I get a wake-up call. What does R stand for in RDBMS is you don't use foreign keys and joins? Please, keep using your FKs, stay safe and don't mingle too much with idiots.
But I still agree that OP's colleague is an idiot.
Re: Ask HN: Do you use foreign keys in relational databases?
#146Re: Ask HN: Do you use foreign keys in relational databases?
#147Re: Ask HN: Do you use foreign keys in relational databases?
#148I agree with your colleague, and I insist on pushing my car everywhere because I fear gas as it is flammable. In other words, the world is full of idiots; and any time I start forgetting about it, I read something like your post and I get a wake-up call. What does R stand for in RDBMS is you don't use foreign keys and joins? Please, keep using your FKs, stay safe and don't mingle too much with idiots.
Re: Ask HN: Do you use foreign keys in relational databases?
#149Fear of RDBMSes is quite common. I used to suffer from it too. It’s just so annoying to have to switch your brain to a different programming paradigm every time you need to do something with the database that you start to make up all sorts of excuses as to why it’s really just better to “do it in the code”. Your coworkers argument about FKs making data migrations difficult is one of them. Another classic is the “join…
Along with the "indexes slow down INSERTs and UPDATEs" argument that you touch on. I mean, it is literally true that indexes make writes slightly slower, and an excessive quantity of indexes (which I have seen) can slow down writes enough to cause problems. But - in general - the slowdown is irrelevant compared with the overhead of querying a table that contains 2 billion rows using, oh, I don't know, a table scan because you don't have even a single index (I have also seen this).