what are the advantages of defining a foreign key

Daniel picture Daniel · Apr 17, 2012 · Viewed 21.1k times · Source

What is the advantage of defining a foreign key when working with an MVC framework that handles the relation?

I'm using a relational database with a framework that allows model definitions with relations. Because the foreign keys are defined through the models, it seems like foreign keys are redundant. When it comes to managing the database of an application in development, editing/deleting tables that are using foreign keys is a hassle.

Is there any advantage to using foreign keys that I'm forgoing by dropping the use of them altogether?

Answer

shark555 picture shark555 · Apr 17, 2012

Foreign keys with constraints(in some DB engines) give you data integrity on the low level(level of database). It means you can't physically create a record that doesn't fulfill relation. It's just a way to be more safe.