Is there a simple way to update multiple tables through a view? Due to performance issues on the server, I have several databases that all have the same layout and same tables but different data in each table. Most of the stored procs involve unioning the tables from each database together:LEFT JOIN( SELECT 1 AS lArea, lProductID, lQuantity FROM Products.dbo.Products UNION SELECT 2 AS lArea, lProductID, lQuantity FROM Products02.dbo.Products UNION SELECT 3 AS lArea, lProductID, lQuantity FROM Products03.dbo.Products)
On occasion new databases are added causing all the stored procedures to need to be updated. This process takes a few hours and is difficult to maintain.I was planning on creating a view or function and then joining on that, the problem however is some of the stored procs update the tables in much the same way: UPDATE p SET p.lQuantity = (p.lQuantity - qs.lAmountSold) FROM Products.dbo.Products p INNER JOIN #tblQtySold qs ON p.lProductID = qs.lProductID WHERE qs.lArea = 1 UPDATE p SET p.lQuantity = (p.lQuantity - qs.lAmountSold) FROM Products02.dbo.Products p INNER JOIN #tblQtySold qs ON p.lProductID = qs.lProductID WHERE qs.lArea = 2 UPDATE p SET p.lQuantity = (p.lQuantity - qs.lAmountSold) FROM Products03.dbo.Products p INNER JOIN #tblQtySold qs ON p.lProductID = qs.lProductID WHERE qs.lArea = 3
Again, this is less than ideal. What would be the best way to handle this situation (changing the infrastructure is not an option)?Thanks