2

What is the difference between MERGE vs. MERGE INTO?
What are the use cases for each?

Surprisingly, I couldn't find any existing question that asks about this difference.

The documentation for MERGE doesn't explain that, too, and it's only used there once in a case which doesn't seem to be relevant for that difference (if any).

3
  • 3
    Downvoters, why? that's a valid question. If you think I "should have known" that [] means optional, ok, fair enough. But Top is also optional, and it has some specific functionality (i.e. take top n records). However, Into just does nothing specific, which is worth the question and the answer. Please reconsider.
    – HeyJude
    Commented Feb 15, 2022 at 16:33
  • Unfortunately, this is a community site and everyone is at their own free will to decide criteria for what they believe should get an upvote or downvote. The general guidance is that a question meet 3 criteria for an upvote, else it could possibly get a down vote. A question needs to show research effort (yours did), needs to be clear (it was), needs to be useful. I think it's the last part you're running into trouble. Some may feel this question brings no usefullness to the community. I wouldn't taken it personal. You've asked a lot of question on this site, and this is your first neg. score. Commented Feb 15, 2022 at 17:51
  • 1
    This question certainly is useful. When looking at the documentation and seeing all of the optional keywords that can be used with MERGE, and how each one gives the MERGE statement certain functionality, it isn't obvious that INTO does not provide any functionality. The documentation doesn't seem to state this anywhere. There is no reason I can think of to downvote, and no reason stated in the comments. I had one developer use INTO and one not using it, and I wanted to know if I need to care or not.
    – Mafu Josh
    Commented Aug 4, 2022 at 13:22

1 Answer 1

5

The syntax diagram for MERGE:

[ WITH <common_table_expression> [,...n] ]  
MERGE
    [ TOP ( expression ) [ PERCENT ] ]
    [ INTO ] <target_table> [ WITH ( <merge_hint> ) ] [ [ AS ] table_alias ]  
    USING <table_source> [ [ AS ] table_alias ]
    ON <merge_search_condition>  
    [ WHEN MATCHED [ AND <clause_search_condition> ]  
        THEN <merge_matched> ] [ ...n ]  
    [ WHEN NOT MATCHED [ BY TARGET ] [ AND <clause_search_condition> ]  
        THEN <merge_not_matched> ]  
    [ WHEN NOT MATCHED BY SOURCE [ AND <clause_search_condition> ]  
        THEN <merge_matched> ] [ ...n ]  
    [ <output_clause> ]  
    [ OPTION ( <query_hint> [ ,...n ] ) ]
;  

Indicates that [ INTO ] is optional. Just like with INSERT it doesn't make any difference whether it's there or not.

1
  • 1
    I think it is good to note that "optional" and "doesn't do anything" aren't the same thing here. Everything in the brackets are optional, but only INTO seemingly "doesn't do anything".
    – Mafu Josh
    Commented Aug 4, 2022 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.