4 ms·
Strange, I was just reflecting this morning how grateful I am that FK constraints are respected. I got a FK constraint violation and without it I would have int
by perrygeo 3y ago
Strange, I was just reflecting this morning how grateful I am that FK constraints are respected. I got a FK constraint violation and without it I would have introduced a bug in my app. Specifically deleting X was doing to delete many child Ys.
If there are any downstream queries that assume the relationship between X and Y, and you accidentally violated that contract, wouldn't you WANT the database to tell you? Without a FK constraint in place, I would just have to know that I needed to update hundreds of lines of (incidentally) dependent code!
It's roughly analagous to the static vs dynamic typing debate. Do you want to discover FK violations at runtime in the future? Or head them off at insert time? Either way, you cannot sweep referential integrity under the rug... you only shift the burden from one place to another.
So I thank my database daily for it's work enforcing FK constraints. Otherwise I'd have to write that code! You can't ignore the lifecycle of references.