About Referential Integrity
First let me brief about the RF<foreign key> concept. If you are thorough on this you will not have this doubt.So letz get going: Referential integrity is about ensuring that relationships between rows in related tables are valid and that you do not accidentally delete or change related data. When referential integrity is enforced in an Oracle database,
you must observe the following rules:
<2>. You cannot delete a row from a primary key table if rows matching it exist in a related table. For example, you cannot delete a row from the JOBS table if there are employees assigned to the job represented by that row in the EMPLOYEE table. However, if cascading deletes are enabled, you can delete a primary key row; all matching rows in related tables are also deleted. <3>. You cannot change a primary key value in the primary key table if that row has related rows. For example, you cannot delete an employee from the EMPLOYEE table if that employee is assigned to a job in the JOBS table. Oracle supports only two kinds of referential integrity: 1. Enabling referential integrity to check values in related tables when you enter data. If the data value is not allowed (as determined by the rules above), the data entry fails and the data is not added to the database. 2. Cascading deletes. By now you should have got the picture!!! SOME MORE HINTS:
You should disable the foreign key constraints in the child tables before issuing the TRUNCATE command, then re-enable them afterwards. Final XPLANATION: QUESTION:Suppose I have the tables:Father(A, B, C),Son(X,Y)
ANS:Primary and foreign keys are defined the parent/child
relationship, you CANNOT delete a record from parent table until it has
record in child table.If your parent table R1 has any child record oracle
does not allow to delete this parent record
But for now the best way is to delete the associative child record of this primary key from the child table then delete it from parent table. for more IDEAS ::::Also look at how to disable/enable constraints!!!! A bit too detailed:but hope this helped you. Channesh
Have a Oracle Question
Oracle Books
Oracle Application
Oracle Home
All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|