How to make a change to "Cascade" using oracle

Asked

Viewed 288 times

0

How can I change my table ID BANDAS_E_ARTISTAS and ensure that other foreign tables also change via PL/SQL?

TABLE BANDAS_E_ARTISTAS

ID NOME_ARTISTICO
01 RAÇA NEGRA
02 OS MENUDOS
03 KELLY KEY
04 LUIZ CARLOS
--------------------------

TABLE ARTISTA

ID NOME_REAL
03 KELLY JOANA
04 LUIZ CARLOS
--------------------------

TABLE BANDA

ID ESTILO
01 PAGODE
02 ROCK
--------------------------

TABLE ARTISTA_EM_BANDA

ID_BANDA ID_ARTISTA
01       04

--------------------------

A table BANDAS_E_ARTISTAS I keep the ID(primary key) of all the identification of the other tables.

1 answer

1


To do this automatically there is no way. You must create a database that receives the new PK and automatically update in all tables referenced.

This trial shall be:

  1. Create a new parent line with the new key value
  2. update all rows in the subordinate table that point to the old main row to point to the new main row
  3. Delete the old parent line
  4. commit

But, if you wish, there is an external library created by a programmer that does this process automatically.

How to install is found at that link

How to use:

In oracle Sqlplus, connected to the created database, run the following command for each table that will be updated from PK :

Exec update_cascade.on_table(‘Nome da Tabela’);

Run the update command for the records you want to update:

UPDATE TABLE_X SET PRIMARYKEY_X = 1000 WHERE PRIMARYKEY_X = 10;

The result will be that where the system finds the PK_X = 10, Trigger will switch in the daughter tables where the value is equal to 10 per 1000, without needing to disable database Constraint.

  • @Guilhermenascimento Use in your POST to talk to users. Any question of the reason, use @ + the User Name. You can see that in the comments your own post is possible to ask the question directly to me. Thank you

  • Sorry, I had not seen that you had already commented on the question. Thank you for alerting me.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.