Joe Joe - 1 year ago 96
SQL Question

Update multiple columns in SQL

Is there a way to update multiple columns in SQL server the same way an insert statement is used?

Something like:

Update table1 set (a,b,c,d,e,f,g,h,i,j,k)=
from table2 t2

Or something like that, rather than like so:

update table set a=t2.a,b=t2.b etc

which can be pretty tiresome to write if you have 100+ columns.

gbn gbn
Answer Source

The "tiresome way" is standard SQL and how mainstream RDBMS do it.

With a 100+ columns, you mostly likely have a design problem... also, there are mitigating methods in client tools (eg generation UPDATE statements) or by using ORMs

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download