Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

update primary key with cascade

WestDraytonJul 2 2010 — edited Feb 3 2012
Lets say i have 10 tables which have Foreign Key defined that all points to one table's Primary Key.
Now i want to update the Primary key value to another value, and, i want all the 10 tables to get this new value into theirs FK-column.
Also note, that also only some of those 10 tables may have such FK-value that is updated in PK-table.
Can i do with some good script this task?

I would like to do somehow this way:
Update PkTable set
Pkcol=NewAvailableValue
CASCADE;
At the moment i am using following approach:
1. From table "user_constraints" find FK-constraints are binded to the Primary key about to be changed, find the list of those tables.
2. Query each table if it has the PK-value in their FK-columns, if has, then update the value to allowed other PK-value.
3. Update PK-table's primary key column value to new value.
4. commit.
This post has been answered by Centinul on Jul 2 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 2 2012
Added on Jul 2 2010
5 comments
12,039 views