I have two SQL Server databases, and I need to write a script to transfer data from database A to database B. Both databases have the same schema.
I have to scroll through the tables, and for each table I have to follow these rules:
- If the element that I am moving does not exist in the target table (for example, the comparison is done in the
Name
column), then I insert it directly. - If the element that I am moving exists in the target table, I only need to update certain columns (for example, update only
Age
and Address
, but not touch other columns)
Can someone help me with this script? Any example would be sufficient. Many thanks
EDIT:
I just need an example for one table. There is no need for a loop, I can process each table separately (since each table has its own comparison column and update columns)
source share