简体   繁体   中英

TSQL - Data pass between DB

TSQL - Data pass between DB

Hello,

as indicated in the subject I'm informing me how to make the transfer of data between two different software. Each with a SQL Server DB. Most likely they are on the same server, so only different times and I can access them both. If the DBs are on different networks, I will implement a VPN.

Example: In the "anagrafica" table of the "DB_a" I have the client's personal data (name, surname, birth, sex ...) In the "anagrafica" table of the "DB _b" I do not have this registry yet.

-Then I would like to pass from the "DB_a.anagrafica" to the "DB_b.anagrafica" this record, obviously with id MAX (DB_b.id) because in the table "DB_b. Registry" there are already records with the relative id. (CASE INSERT);

  • Or if a data is updated on DB_a.anagrafica, the update must be performed on the "DB_b.anagrafica" fields;

  • In case a new record must be inserted in a weak table of "DB_b", ex. "DB_b.pagamenti" there is a unique id of the table and an external key that points to the id of the strong personal data table; (maybe the data in the weak table could have two more fields start_date and data_fine), this table is 1: N

-The two DBs have been written by two different software houses so most likely the field types may differ. (characters, numeric, date and time, etc. ..) then CAST, CONVERT etc.

  • In the end there could also be a return figure to complete the whole es. from "DB_b". registry to "DB_a.anagrafica".

That said there is a software that already exists that puts you in the middle of the two DB is an interchange? (most likely to be scheduled with windows scheduler). Or a store procedure.

Do you have more directions to give me?

Thanks in advance

The most important question in such a scenario is: Is there a leading system?

The most difficult in such a scenario is: dealing with concurrency.

For your scenario it seems to be fairly easy to answer your initial question ("TSQL - Data pass between DB"):

If both databases can "see" each other, just implement a linked server . You can read about OPENQUERY and follow the links at the bottom of this page.

Typical approaches are

  • shift the changes directly to the target (in case of a leading system)
    Use timestamps to look for concurrent changes

  • shift all changes to a staging table (one for both or one for each)
    Use any appropriate tool (T-SQL or any programming language you prefer) to read this/these table(s) regularly, deal with business rules and update both systems accordingly.

You might think about identically structured staging tables in both systems linked by standard replication.

As your systems are similar but not identical there won't be any magic-automatic-wonder-tool ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM