If your data is divided into different database(s) and you need to update your main databse using those data from different database(s).
Let us assumes that, your main database Name is MainDatabase, and your other database(s) are likeClientDataBase1, ClientDataBase2 (We will call all those database as client database). Following are the simple steps to update the table from the different database(s). Step1 ========= select PK_ID,COL_to_CHANGE INTO [MainDatabase].[dbo].[ from ( select PK_ID,COL_to_CHANGE from [ClientDataBase1].[dbo].[ union all select PK_ID,COL_to_CHANGE from [ClientDataBase2].[dbo].[ ) as b This will create the Table named [TempTable] and insert all the results from the select statements Step2 ========= UPDATE F SET F.COL_to_CHANGE= X.COL_to_CHANGE from [MainDatabase].[dbo].[ ON X.PK_ID=F.PK_ID IF [TempTable] is already available in [MainDatabase], use the following step instead of step1 Delete * from [MainDatabase].[dbo].[ Insert into [MainDatabase].[dbo].[ select * from ( select PK_ID,COL_to_CHANGE from [ClientDataBase1].[dbo].[ union all select PK_ID,COL_to_CHANGE from [ClientDataBase2].[dbo].[ ) as b
Hi,
Welcome to my blog. This is my introductory post to introduce myself. In this blog you will find the numerous new things related to IT fields. Definitely you will enjoy the blog with accessing this blog.
| Author
Prakash Samariya is an IT Professional. He has 10+ years of experience in various domains with his expertise.
Archive
Categories
RSS feed |
RSS feed