Foreign Key Constraints Debate

The cluster centers on debates about using foreign key constraints in databases, weighing their role in maintaining referential integrity against drawbacks like performance impacts, schema migrations, and scalability issues in large apps.

📉 Falling 0.3x Databases
2,709
Comments
20
Years Active
5
Top Authors
#2477
Topic ID

Activity Over Time

2007
5
2008
8
2009
37
2010
37
2011
38
2012
65
2013
116
2014
75
2015
80
2016
79
2017
102
2018
179
2019
290
2020
150
2021
257
2022
401
2023
333
2024
266
2025
184
2026
7

Keywords

e.g WITH BS OPTION IMO SQL ORM RDBMS PK JOIN foreign key constraints keys database table columns column integrity deleted

Sample Comments

datalopers May 26, 2022 View on HN

Database-enforced FKs are an overrated crutch anyway. Apply the third normal form, utilize transactions correctly, and you won't ever need them.

anton_gogolev May 3, 2018 View on HN

How could foreign keys ever be a "hassle"?

damncabbage May 20, 2012 View on HN

I take it you don't use foreign key constraints, then.

moltar Nov 25, 2021 View on HN

Do you not think about relational integrity?

QuiCasseRien Sep 6, 2022 View on HN

"use FK, you fools!"FK maintains your database integrity. If you care about data, just use it !

greggyb Nov 8, 2019 View on HN

The suggestion is to not use foreign key constraints in the database.The suggestion is not to eschew columns which might be JOINed on in a query.I.e. "Don't enforce FK relationships with a constraint in the DB. Make sure the values in both tables which may be joined are consistent by using application code to enforce this."

lofaszvanitt Jan 24, 2024 View on HN

Sanely created schema does not have these kinds of problems ;). Plus FKs are a performance impact.

Jarwain May 19, 2021 View on HN

Do you know if foreign keys tend to be a problem on postgresql as well?

adammarples Oct 17, 2022 View on HN

Yes, the one in which you considered FK constraints to be a waste of time

sleepyhead Aug 20, 2014 View on HN

So you don't want support for real foreign keys?