Home > Alter, Error Messages, Insert, Joins, SQL Queries, SQL Server, Stored Procedures, T-SQL, Tips & Tricks > Understanding MERGE Transact SQL Statement

Understanding MERGE Transact SQL Statement

By using “Merge”, you can perform insert, delete and update on a table in a single SQL statement. This helps in synchronizing the tables as well.

However while using merge there are several points that you need to keep in mind. Few

  • In a “Merge” statement, a “When Matched” clause with a search condition cannot appear after a ‘When Matched’ clause with no search condition.
  • A “Merge” statement must be terminated by a semi-colon (;).
  • An action of type ‘DELETE’ is not allowed in the ‘WHEN NOT MATCHED’ clause of a MERGE statement.
  • At least one of the three MATCHED clauses must be specified, but they can be specified in any order. A variable cannot be updated more than once in the same MATCHED clause.
  • Any insert, update, or delete actions specified on the target table by the MERGE statement are limited by any constraints defined on it, including any cascading referential integrity constraints.

Few examples of merge are as given below.

Read more…

 

 

Advertisements
  1. April 10, 2013 at 4:19 am

    What i do not realize is actually how you’re no longer really a lot more smartly-preferred than you might be now. You’re so intelligent.

    You understand thus considerably in terms of this
    matter, made me in my opinion imagine it from numerous numerous angles.
    Its like women and men don’t seem to be involved until it’s one thing
    to do with Woman gaga! Your individual stuffs great.

    At all times handle it up!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: