T-SQL MERGE INTO

  • Hello experts,

    I'm learning about the T-SQL MERGE statement and see that there is an INTO clause specified in the syntax definition. However, I don't see it explicitly explained in BOL.

    [ WITH <common_table_expression> [,...n] ]

    MERGE

    [ TOP ( expression ) [ PERCENT ] ]

    [ INTO ] <target_table> [ WITH ( <merge_hint> ) ] [ [ AS ] table_alias ]

    USING <table_source> ...

    It appears to be optional because I have read many tutorial pages that exclude it, for example, as follows:

    MERGE [Destination Table] AS Target

    USING [Source Table] AS Source

    ON Target.KeyField = Source.KeyField

    Ref.:

    http://www.purplefrogsystems.com/blog/2011/12/introduction-to-t-sql-merge-basics/

    Could someone explain the purpose of the INTO clause, specifically when to use or not use it?

    Thanks for any help!

    - webrunner

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

  • It's a readability word. You can omit it if you choose (much like the word AS when aliasing columns).

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • Phil Parkin (12/18/2015)


    It's a readability word. You can omit it if you choose (much like the word AS when aliasing columns).

    Thanks! That explains it. 🙂

    - webrunnr

    -------------------
    A SQL query walks into a bar and sees two tables. He walks up to them and asks, "Can I join you?"
    Ref.: http://tkyte.blogspot.com/2009/02/sql-joke.html

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply