Foreign keys provide consistency in the DBMS. That is, no child row can refer to a nonexistent parent.
There is a school of thought that consistency rules must be followed by application code, but this is inefficient and error prone. Even if your code is perfect and error free and never enters the wrong link, how can you be sure that all other codes that access the same database are also perfect?
When restrictions apply in an RDBMS, you can rely on consistency. In other words, the database never lets you make changes that break links.
When the restrictions are met by the application code, you can never be sure that there were no errors in the database. You find yourself working with frequent SQL scripts to catch broken links and fix them. The extra code that you must write to do this far exceeds any operational cost for the RDBMS management sequence.
source share