Reputation: 3360
I have just started internship at a small software house and I am working on an ERP. My team lead has forbidden me to create any relationships in the database. As this is my internship I was shocked because till now I have read that relationships are necessary for ensuring data integrity. My team lead told me that we can enforce the data integrity at the front end. After some research I found out that foreign keys do make the db slower but Indexing foreign keys can increase performance.
If indexing foreign keys increase performance then what would be better out of the two below:
1.) Ensuring data integrity rules at application layer
2.) Indexing Foreign Keys
Thanks for help.
Upvotes: 11
Views: 3286
Reputation: 7169
In general, the more complex your data model becomes, the greater the hit to performance you will experience. However, unless your database is very large, your hardware resources very minimal, or your queries very complex, you probably will not be hindered by adding enforced relationships in your database. That is obviously a subjective statement, but "acceptable performance" is a very subjective concept that will vary from project-to-project.
The heart of your colleague's argument is correct, though, and here are a few reasons why:
That said, here is why those arguments mostly don't matter:
These all depend upon your RDBMS and project's specifications, but are good rules of thumb. In general, I would say that unless your database is so large that enforcing relationships becomes prohibitively slow, or your model is so simple that relationships are pointless (in which case, why are you using an RDBMS?), it is better to enable data integrity and relationship constraints.
Upvotes: 10