Monday, July 14, 2008

SQL Server Update table with inner join : update one table based on the contents of another table

Many times we need to update the contents of one table based on the contents of another table.

Have you ever found yourself in such situation ?

Well the simplest approach for that is by using the aliases.

For example if we wish to update a table tableA based on the contents of the table tableB then by using aliases we can do it in the following way:




Update a set a.field = b.field from tableA a inner join tableB b on a.primaryKey=b.foreignkey

And that’s it.