• sqlPirate_Fl (3/7/2013)


    So I've been reading up on Merge and have been experimenting with it lately in my 2012 environment.

    I've run a few tests and was curious if aside from the readability improvements offered, if you found it useful in your production environment. Opinions welcome.

    Also for your source tables, I've only tested against @temp tables so far, but did you have better performance with #tables or physical tables? In the latter two, assuming proper indexing added.

    Thanks for reading.

    I use MERGE often. In addition to the scenario where multiple operations are useful, I also use it in place of single UPDATE...FROM/JOIN operations because it protects us from ambiguously updating the same row multiple times due to an improper JOIN clause.

    P.S. I find MERGE incredibly strong, but dangerous during a delete if you're clause isn't accurate. I like it personally, but before I start using it in real life situations just looking for the opinions of others who've used it successfully in their day to day work environment.

    I would say that a MERGE that deletes data is no more dangerous than a DELETE...FROM/JOIN that deletes data. The risk in writing an improper JOIN clause seems to be about the same. Maybe not initially though, but once you learn and are comfortable with the MERGE syntax.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato