0 votes
1 view
in SQL by (20.3k points)

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

where table1.id=table2.id

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.

1 Answer

0 votes
by (40.3k points)

Try using below code:

UPDATE table1 

SET a = t2.a, b = t2.b, .......

FROM table2 t2

WHERE table1.id = t2.id

Note: The above code will work in most SQL dialects, excluding Oracle.

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !