Ask HN: Are foreign key constraints still useful?

1作者: doganugurlu5 天前原帖
There was a time we offloaded a lot of business logic to the database server. Well, it was the only server &quot;up&quot; so it felt like it was ok.<p>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 &quot;SQL server is where everything lives&quot; strategy. Not sure, bit of a blur.<p>But, we still offload some logic to the database in the form of constraints, most popular one being the foreign key constraint.<p>In 15+ years of professional programming, I can&#x27;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.<p>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.<p>I feel like DB constraints are relic from a bygone era and the requirements that necessitated DB constrains are long gone.<p>Do you agree or am I going crazy?
查看原文
There was a time we offloaded a lot of business logic to the database server. Well, it was the only server &quot;up&quot; so it felt like it was ok.<p>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 &quot;SQL server is where everything lives&quot; strategy. Not sure, bit of a blur.<p>But, we still offload some logic to the database in the form of constraints, most popular one being the foreign key constraint.<p>In 15+ years of professional programming, I can&#x27;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.<p>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.<p>I feel like DB constraints are relic from a bygone era and the requirements that necessitated DB constrains are long gone.<p>Do you agree or am I going crazy?