Ask HN: Are foreign key constraints still useful?
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?
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.