frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Ask HN: Are foreign key constraints still useful?

2•doganugurlu•2h ago
There was a time we offloaded a lot of business logic to the database server. Well, it was the only server "up" so it felt like it was ok.

So we piled on a ton of business logic on the database server. Triggers, stored procedures, you name it, we did it. And then it dawned on us that the code that lives in the database server extremely is unmaintainable - or MS decided to stop pursuing the "SQL server is where everything lives" strategy. Not sure, bit of a blur.

But, we still offload some logic to the database in the form of constraints, most popular one being the foreign key constraint.

In 15+ years of professional programming, I can't remember a time DB constraints protected a system I was working on. Almost 99% of the time, DB constraints pop up when I am making changes to my local environment, and the 1% was when there was a fire, and I had to make changes to a prod database in an urgent fashion. I never saw a log line that indicated DB constraints to be a useful protection.

And then there is the NoSQL world where obviously life goes on without these constraints and no one is trying to port foreign key constraints to NoSQL.

I feel like DB constraints are relic from a bygone era and the requirements that necessitated DB constrains are long gone.

Do you agree or am I going crazy?

Comments

diavelguru•2h ago
You answered your own question in the description. "DB constraints pop up when I am making changes to my local environment” and that gave you the confidence to promote to QA, Staging and finally Production. A well tested application will find those problematic issues long before it goes to prod. I’m just glad that all business logic is not thrown in the DB as in the past. The separation makes for a much quicker and robust system. Don’t think DB constraints are a relic they are very much a part of the relational database management system and still used in those systems very successfully. Another topic for another thread is the relevance of the RDBMS itself not just one subset of it.
barbazoo•2h ago
I appreciate FK constraints as a form of schema documentation.
PaulHoule•2h ago
Automated tools can use 'em too.
PaulHoule•2h ago
People were having this conversation circa 2000 when MySQL didn't have FK constraints, transactions and many features other databases had.
SvenL•2h ago
I think Fk constraints are still valid and a good thing to do.

Like you mentioned, you changed something and they pop up. You define that there is a necessary relationship between certain things and define it once in your schema. Your sql server takes care of enforcing it. You don’t need to remember every time about this relationship. So there is one thing less you need to take care of/which can cause issues.

Cerebral perfusion monitoring with ultrafast power doppler imaging

https://www.nature.com/articles/s41598-025-04338-0
1•PaulHoule•1m ago•0 comments

Claude is down?

https://claude.ai/new
1•williamtrask•1m ago•0 comments

BackupGuardian – Validate Database Backups Before Migration (Open Source)

https://www.backupguardian.org
1•neural_drift•2m ago•1 comments

Dark personalities: how psychopathy shapes online political participation

https://www.nature.com/articles/s41599-025-05195-y
1•mylifeandtimes•3m ago•0 comments

AI search firm Perplexity makes $34.5B surprise bid for Google Chrome

https://www.cnn.com/2025/08/12/tech/perplexity-google-chrome-bid
1•rawgabbit•5m ago•1 comments

NYC Mayor Adams Uses Free Internet to Expand Police Surveillance at NYCHA

https://nysfocus.com/2025/08/11/eric-adams-nycha-nypd-cameras-surveillance
1•h2si•6m ago•0 comments

Perrier scandal bubbles up as French parliament slams cover-up

https://www.france24.com/en/live-news/20250519-perrier-scandal-bubbles-up-as-french-parliament-slams-cover-up
1•gnabgib•10m ago•0 comments

Why does /etc/resolv.conf point at 127.0.0.53?

https://unix.stackexchange.com/questions/612416/why-does-etc-resolv-conf-point-at-127-0-0-53
1•tanelpoder•11m ago•0 comments

Fabricated data in posts.xml for multiple/all data dumps [Stack Overflow]

https://meta.stackexchange.com/questions/412018/fabricated-data-in-posts-xml-for-multiple-all-data-dumps
3•throwawaybutwhy•12m ago•1 comments

Vibecoding is skeuomorphic because code generation is slow

https://whoo.ps/p/vibecoding-is-skeuomorphic-because-code-generation-is-still-slow
1•libovness•17m ago•0 comments

Interactive Reasoning Benchmarks – Arc-AGI-3 Preview

https://www.youtube.com/watch?v=3T4OwBp6d90
1•itsgrimetime•20m ago•0 comments

Ask HN: Has the ChatGPT 5 web chat become more agreeable?

1•bn-l•22m ago•0 comments

GPT-5 Set the Stage for Ad Monetization

https://semianalysis.com/2025/08/13/gpt-5-ad-monetization-and-the-superapp/
4•9cb14c1ec0•29m ago•2 comments

Show HN: Mirroranimage.com – Flip or Mirror Any Image in Seconds

https://www.mirroranimage.com/en
1•devxiyang•30m ago•0 comments

$160M VC-backed company just killed my EU trademark for a small OSS project

5•marcjschmidt•31m ago•0 comments

Show HN: A fun side project on chivalry and virtues

https://www.chivalrytest.online/
1•z946719919•32m ago•0 comments

The Ceph community on Reddit has been banned

https://lists.ceph.io/hyperkitty/list/ceph-users@ceph.io/thread/5L5DRBN4TQZILJKXT43DNT7TILUSFLZ3/
3•patrakov•34m ago•0 comments

LLM Hallucination Seems Like a Big Problem, Not a Mere Speedbump

https://freddiedeboer.substack.com/p/llm-hallucination-seems-like-a-very
2•blueridge•37m ago•0 comments

Please Don't Promote Wayland

https://stoppromotingwayland.netlify.app/
34•PKop•40m ago•24 comments

We used CustoQ to turn 40% of "lost" customers into paying ones

https://custoq.com/blog/reduce
1•sdotdev•40m ago•0 comments

BlueDwarf a social media site that works on all your devices

https://bluedwarf.top/cackle/index.php
2•lardbgard•42m ago•4 comments

$160M VC-backed company just killed my EU trademark for a small OSS project

https://old.reddit.com/r/ExperiencedDevs/comments/1mopzhz/comment/n8e1sog/
3•marcjschmidt•44m ago•0 comments

RIP Dame Stephanie Shirley, who changed women's role in the tech industry

https://www.bbc.com/news/articles/c4gzzlp7p3po
1•tagawa•45m ago•1 comments

Gurps Cyberpunk

https://en.wikipedia.org/wiki/GURPS_Cyberpunk
4•gessha•45m ago•0 comments

Ask HN: Would you swap your desk for a restaurant shift?

2•dorcy•51m ago•3 comments

Ancient DNA Studies Find Black Africans in England, in the Early Middle Ages

https://www.haaretz.com/archaeology/2025-08-13/ty-article/ancient-dna-studies-find-black-africans-in-england-in-the-early-middle-ages/00000198-9df8-d1fc-a3d8-fdfccd6b0000
1•wslh•54m ago•0 comments

AI Eroded Doctors' Ability to Spot Cancer Within Months in Study

https://www.bloomberg.com/news/articles/2025-08-12/ai-eroded-doctors-ability-to-spot-cancer-within-months-in-study
29•zzzeek•55m ago•16 comments

Inside Silicon Valley's Growing Obsession with Having Smarter Babies

https://www.wsj.com/us-news/silicon-valley-high-iq-children-764234f8
4•impish9208•58m ago•1 comments

What If It Works? The Autonomous Truck Revolution

https://jsherwin.substack.com/p/what-if-it-works-the-autonomous-truck
3•ajd555•59m ago•0 comments

Generative Answers Are Reshaping Google Search

https://procurefyi.substack.com/p/how-generative-answers-are-reshaping
2•beepbeepbee•1h ago•0 comments