Update Data from Two Databases with Unique References

By: Ahmar
DOWNLOAD AS PDF

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:

UPDATE cust
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.

Comments are welcome!

latest news

01

5 signs your company needs an ERP

An ERP system captures information from all departments, and it may be time for you to implement it within your organization. Here are 5 signs that make it clear your business will benefit from an ERP system.

02

7 Benefits of an ERP System For Your Business

ERPs manage the core processes of an organization – from HR to sales to finance – and house all the data. Many ERPs also offer increased visibility, analytics, and efficiency across the company. Let’s explore some of the benefits of running your business on an ERP system

03

8 Benefits to Adopting DevOps into your Organization

Under DevOps, a “product-first” approach, companies align development projects with the business goals of operations so teams can jointly build, test, release, and maintain new digital applications more frequently and more efficiently. What benefits does DevOps offer?

Copyright© 2018 alligatortek. All rights reserved.