• Venkataraman R (10/28/2013)


    The dangerous side of MERGE talks about how MERGE statement with wrong usage can wipe out data: http://www.sqlservercentral.com/articles/MERGE/97867/#.Um5Zwk6LY0Q.twitter

    I saw that article (you'll probably notice a rather familiar reply in that discussion 😉 ) and although it points out an interesting technique using a CTE, it also completely misuses the logic of the ON clause coupled with "WHEN NOT MATCHED BY SOURCE", and then tries to fix it.

    I just don't understand why MERGE seems to get so many warnings about how it can be misued, when I don't think it is any more or less dangerous than making a mistake when writing a DELETE which uses a correlated subquery.

    The warnings kind of distract the reader from understanding the fairly intuitive logic (although admittedly cumbersome syntax!)