Can someone please simplify this merge sql server statement for me please

Can someone please explain this in lay mans terms to me please

        SELECT TID, name, address
        FROM T [s]
      ) d on 0 = 1
THEN INSERT (name, address)
    VALUES (name, address)
OUTPUT d.TID as oID, Inserted.TID as nID
INTO @t;
Who is Participating?
Shaun KlineConnect With a Mentor Lead Software EngineerCommented:
The MERGE statement uses the SELECT statement to compare against your target TABLE T, performing a match between source and target on 0 = 1. For any source data rows that do not match a target row, the source row is inserted into the target row. The ID from the source table and the newly created IID from the target table are then output into a variable table @t.

That said, because the match is performed using 0 = 1, this statement will basically insert every row in your source table into your target table. Since the source and target use the same table, you are duplicating every row in T.
Éric MoreauSenior .Net ConsultantCommented:
All the rows (name and address fields only) from table T are re-inserted into the same table (because of "on 0 = 1")
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.