I have encountered a SQL Server query along the following lines:
UPDATE R SET R.fieldX = C.fieldX,
R.fieldY = C.fieldY,
R.fieldZ = C.fieldZ,
...etc, about 20 field assignments....
FROM TableA R JOIN TableB T ON T.fieldA = R.fieldA AND T.fieldB = R.fieldB JOIN tableC C ON T.fieldC = C.fieldC AND T.fieldD = C.fieldD AND R.fieldE = C.fieldE AND R.fieldF = C.FieldF WHERE T.fieldE = 0 AND R.FieldE = 0
The self-referential nature of it (updating a table that is participating in a multiple-table join) looks suspicious to me, and whilst it works, where the tables have large numbers of rows it consumes a huge amount of disk space before completing (if it completes at all before running out of drive space).
The purpose of the query is to transfer data from the various joined tables to the target table.
Is there a more efficient way of accomplishing this?