Update Data from Two Databases with Unique References

By: Ahmar

While researching another SQL Server-related issue, I found many people looking to update the data from one database table to another database table with both tables containing unique references. I thought to share my experience where I had to copy the Customer Email Addresses along with some other information from the QA Environment Database to the Performance Testing Environment Database.

Here is how I did that:

SET cust.ContactEmail = originalCust.ContactEmail
FROM DBName1.dbo.Customer cust, DBName2.dbo.Customer originalCust
WHERE cust.custID = originalCust.custID

The statement above is written very similarly to the SELECT statement-where we join two or more tables to retrieve data.

In this example:

  • Instead of SELECT, we have an update statement.
  • Instead of SELECT Columns we have SET columns that update the data automatically.

About Ahmar
Ahmar Arshi is the Director of Software Development at alligatortek.

alligatortek is a Chicago custom software and application development firm that began partnering with clients 25 years ago to develop game-changing applications for its clients. alligatortek is recognized as a best-in-class partner, innovator and employer. The firm is a two-time winner of the Chicago Innovation Awards and a 2015 Microsoft Partner of the Year. alligatortek is a four-time winner of the 101 Best & Brightest Companies to Work For in the Nation.

Copyright © 2020 alligatortek. All rights reserved.