Copy tables to another bank while maintaining relationships

Asked

Viewed 35 times

1

I’m trying to send some records from one bank (bank A) to another (bank B) that contains the same structure. They are records of 3 tables, 1 table(patient) contains MAIN records and the other 2(file and scheduling) are COMPLEMENTARY data(foreign key with the MAIN).

Setting:

inserir a descrição da imagem aqui

My difficulty is with the Ids. Because the bank A and bank B already have records and the Ids of one already exists in the other. I want to ignore the IDS of the Origin table, but I cannot lose the relationship with the other 2 tables.

I tried to make a:

 insert bancoB.paciente
     USANDO dados de:
 select ... bancoA.paciente 

But as I have relationships to take too, when making the children tables Inserts the ID table FATHER(patient) will get lost.

**

Follows the properties of the 3 tables:

**

Main table:

inserir a descrição da imagem aqui

Table Filho1:

inserir a descrição da imagem aqui

Table Filho2:

inserir a descrição da imagem aqui

  • if it is not replication can change the IDS, then what I see might help was, make a cursor that takes the data of "patient", make the Insert in the other bank, take the new ID and make the Insert of the other tables using the new ID, has to be done one by one, so a cursor can help there

  • Cool, I thought about this strategy, but I couldn’t reproduce, it should be a precedent? has some example of code?

No answers

Browser other questions tagged

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