Ask HN: Do you use foreign keys in relational databases?
21–30 of 251 posts
Re: Ask HN: Do you use foreign keys in relational databases?
#22Re: Ask HN: Do you use foreign keys in relational databases?
#23I think trying to manage consistency in your application is probably a bad idea.
Re: Ask HN: Do you use foreign keys in relational databases?
#24Re: Ask HN: Do you use foreign keys in relational databases?
#25Why not just turn off foreign key checks during migrations and after validating the data, turn them back on? SQL Server lets you do this.
Re: Ask HN: Do you use foreign keys in relational databases?
#26I'm going to assume that by "foreign keys", you mean "foreign key constraints" where the DB itself is insisting on particular relationships. There are a few different schools of thought. I will list them, but the important thing to remember is not to be dogmatic. They are all right or wrong depending on your circumstance. One school of thought says "I want all data in my DB to be normalized. I want it to be right whe…
> At the volumes my organization works with, it is very difficult to write performant SQL queries that use JOINs and other relationships as a developer - even as a DBA! - and often much easier, for me, to write performant application code. How can this possibly be true? Won't that result in sending unnecessary data over the wire, stressing network and SQL buffer? What are these queries and what are these volumes? I j…
Re: Ask HN: Do you use foreign keys in relational databases?
#27FK’s is what makes a relational database “relational”. It sounds like your colleagues want NoSQL (key-value) given their no JOINs policy.
"Relational" comes from https://en.wikipedia.org/wiki/Relational_model Table = relation
This example makes it pretty clear: https://en.wikipedia.org/wiki/Finitary_relation#Example
I always thought it was referring to foreign keys too. Pretty bad name in hindsight.
Re: Ask HN: Do you use foreign keys in relational databases?
#28Re: Ask HN: Do you use foreign keys in relational databases?
#29Why not just turn off foreign key checks during migrations and after validating the data, turn them back on? SQL Server lets you do this.
But you could get duplicate key errors when turning fk on. A customer of mine uses UUIDs as keys. That makes almost impossible to get duplicate keys and removes any problem with moving data from one db to another. Reading UUIDs is a minor pain though.
Re: Ask HN: Do you use foreign keys in relational databases?
#30I'm going to assume that by "foreign keys", you mean "foreign key constraints" where the DB itself is insisting on particular relationships. There are a few different schools of thought. I will list them, but the important thing to remember is not to be dogmatic. They are all right or wrong depending on your circumstance. One school of thought says "I want all data in my DB to be normalized. I want it to be right whe…
> At the volumes my organization works with, it is very difficult to write performant SQL queries that use JOINs and other relationships as a developer - even as a DBA! - and often much easier, for me, to write performant application code. How can this possibly be true? Won't that result in sending unnecessary data over the wire, stressing network and SQL buffer? What are these queries and what are these volumes? I j…
Of course each scenario is different, YMMV, and as always "it depends".