MySQL Forums
Forum List  »  InnoDB

Basic question about coding with FKs
Posted by: Steven R
Date: September 03, 2008 12:42PM

I've done some smaller projects in the past, usually just involving a few MyISAM tables with no explicit primary/foreign keys defined. Trying my hands on a bigger project now. I read a lot about keys, normalization etc. and I understand FKs help enforce integrity. People also say it makes code simpler.

But how does that really help with the app code apart from automatically cascading deletes? It seems that when you try to manipulate data that violates FK rules, the DB throws an error. Then you need to handle the error in your code. Or, better, you write your code in such a way that it adheres to and mimics the FK constraints in the first place. But in that case, why bother defining PKs and FKs?

As far as I can tell at this point, you still need to insert/update data across different tables separately with different code statements. It's not like the PK/FK relationship helps auto-populating tables. And you still have to write your code to emulate the relationships. So how do keys make code simpler?



Edited 1 time(s). Last edit at 09/04/2008 10:38AM by Steven R.

Options: ReplyQuote


Subject
Views
Written By
Posted
Basic question about coding with FKs
4656
September 03, 2008 12:42PM
3312
September 11, 2008 01:40PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.