-
foreign key and primary key
Hi,
I have a table DEPTT and STAFF .In DEPTT there is a primary key D_ID which is foreign key in STAFF.Changes made in DEPTT table for D_ID results in
."violated - child record" error.This is working correctly.However
when I change D_ID in STAFF the record gets updated and no error is thrown.
My understanding is that it should reflect back in the main parent table (DEPTT) also.
Please let me know if I am thinking right.
Thanks in advance,
dhawanmansi
-
Originally Posted by dhawanmansi
My understanding is that it should reflect back in the main parent table.
Wrong assumption - doesn't work that way.
The only reason you are not getting an error when updating STAFF.D_ID is because the new value already exists in DEPTT.D_ID
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
thanx 4 your rply.
But i am still not able to understand that according to the definition of a database, if one change is made in some table then that change must be reflected back in other table as well in order to maintain data consistency.
But if i am making any changes in the DEPTT table then why those changes are not made in the staff table. In fact, it is giving an error even when i am making changes in the parent(deptt) table and not allowing me to change the values in my table
-
Originally Posted by dhawanmansi
But i am still not able to understand that according to the definition of a database, if one change is made in some table then that change must be reflected back in other table as well in order to maintain data consistency.
Oracle takes care of protecting data integrity by returning and error when issued DML is bound to violate defined referential integrity.
If you want to change data you have to do it - Oracle does not do it for you.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
But even when i m trying to change my data in every table where it is required, it gives an error. So how can i change my data ?????
-
Originally Posted by dhawanmansi
But even when i m trying to change my data in every table where it is required, it gives an error. So how can i change my data ?????
That's the beauty of referential integrity. Oracle will protect your data even from you
Here is a way...
1- Insert new row in parent table.
2- Update row in child table.
3- Delete old row in parent table - providing it has no other childs and you don't need it anymore.
Please do it in a single transaction.
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|