Updating multiple tables sql server

But in many cases this only provides a modest improvement as each UPDATE operation still requires a round-trip communication with the database server.In the case where the application server and database server are on different hosts, the round-trip will involve network latency as well.So is structured so that approaches which are generic across different SQL databases are expressed in a base class, and approaches which only work for specific SQL databases are expressed in a subclass.An object of the relevant class is instantiated when the call is made, and control then passed to the implementation relevant to the database in use.The dominant factor in the time taken to complete the overall operation tends to be the “admin” work in conveying the application’s intention to the database server rather than the actual updates to the database.

Optimising the number of UPDATEs by grouping the distinct SET values can be done in a way which is compatible with most common SQL databases. FROM approach requires knowledge of the specific SQL database being used.

So, given a list of updates to apply we could effect them using the following steps: So in the example above we can reduce five statements to four. But now the number of statements is no longer directly dependent on the number of rows requiring updates.

Even if we wanted to update a thousand rows with different values, we could still do it with four statements.

Column1 = 'name' FROM Table1 T1, Table2 T2 WHERE T1= T2and T1= '100' UPDATE Table2 SET Table2.

Hi All, I want to update multiple columns from multiple tables in a single UPDATE Query...

and we could persuade the database server to apply those updates to the target table?

You must have an account to comment. Please register or login here!