I have two SQL Server databases A and B
They both contain a table named Users with the columns name, Age, Salary
I want to write a script to insert the Users from database A into database B (if they don’t already exist based on Name)
So basically I need this in SQL script:
Foreach (UserA in DatabaseA.Users)
If UserA.Name does not exist in DatabaseB.Users
Insert UserA in DatabaseB.Users
Thanks a lot for any help
one way, no need to loop, you can do it set based
There are more ways to do this by using IN, OUTER JOIN, EXCEPT, some examples here Select all rows from one table that don’t exist in another table