T-SQL Update Table From Another Table

Let say you have two tables and you want to update values in first table with values from second table. That could be for example if you have Product table and you have to load new prices and discounts from Import_Prices table.

The T-SQL code to update data could look like this:

In this case column ID of table Product corresponds to column ProductID of table Import_Prices .

Be careful to define relationship correctly and eventually filter only needed rows with WHERE clause. UPDATE command could change all table rows if you don’t narrow it correctly, so be sure that you have backup created before using ad-hoc UPDATE query :)

Share on FacebookShare on LinkedInEmail this to someoneTweet about this on TwitterShare on Google+