I know that a foriegn key is a reference key( and for refrential integrity purposes) but can anyone explain to me why you need a foriegn key? I mean an example why you need a foreign key constraint?
Printable View
I know that a foriegn key is a reference key( and for refrential integrity purposes) but can anyone explain to me why you need a foriegn key? I mean an example why you need a foreign key constraint?
Some practical examples may be helpful.
You would not want an employee working in a department that was not part of the department table.
You would not want to have line items in the Order Detail table that did not have a corresponding Order Number in the Order table.
In short, constraints are one way of enforcing business rules.
Hope that helps.
Foriegn key is the bread and butter of Relational Database.
Real life example:
You have two table Customers and Payments, you don't want to send bills to people who are not in the Customer table, that is why you have PK and FK.
More of a development flavour rather than that of admin. So moving it to the development forum from the administration forum
Sam
I just don't get it. Can you guys explain in another way? I have enabled foreign key constraints. I know the syntax,etc but I still want to understand the reson why foreign keys are important
What does your application do? That is, what is its purpose in your organization?
It's used for preventing any unlogical data modifications in tables related by FK. If any DML statements violate referential integrity (i.e. FK constraints), Oracle will not execute and will give an error.
I think dKnight explains this issue very clear.