Monday, July 07, 2014

Update Table from Another Table in SQL Server

Update Table from Another Table in SQL Server:  A simple scenario demonstrating how we can update Persons table with data from Employees table using update statement.  A simple but very effective query which can saves you from creating unnecessary cursor for updating from different tables.  By performance wise also Update statement is more efficient compared to creating update cursor.


Update DestTbl
Set DestTbl.ColumnABC = SourceTbl.ColumnXYZ
FROM    Employees SourceTbl
JOIN    Persons DestTbl
ON      DestTbl.KeyCol1 = SourceTbl.KeyCol5


Here:
SourceTbl stands for Source Table
DestTbl stands for Destination Table



No comments:

Most Recent Post

Subscribe Blog via Email

Enter your email address:



Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape