sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
mcmreddy@gmail.com's Avatar

Advantages of "MERGE INTO"


Question posted by: mcmreddy@gmail.com (Guest) on November 12th, 2005 11:36 AM
Hello,
Is there any advantage of using "MERGE INTO" SQL instead of using
"EXISTS" AND "NOT EXISTS" in DB2?.

Thanks,
--Chandra

1 Answer Posted
Serge Rielau's Avatar
Guest - n/a Posts
#2: Re: Advantages of "MERGE INTO"

Join Bytes! wrote:[color=blue]
> Hello,
> Is there any advantage of using "MERGE INTO" SQL instead of using
> "EXISTS" AND "NOT EXISTS" in DB2?.
>
> Thanks,
> --Chandra
>[/color]
If all you want to do is an UPDATE then it's a wash in teh ideal case
for MERGE.
If you want to do UPSERT then MERGE is meant to outperform.

MERGE has pretty heavy semantics attached to it. Only if everything is
just right is it a true winner.
Just right means:
ON clause joins on a unique keys and DB2 can figure it out.
If the row merged is a single row, DB2 needs to be able to prove that to
avoid dams between the INSERT and the UPDATE (unique key enforcement).

In FP9 DB2 has gotten quite sophisticated about MERGE and it's used by
SAP in BW and AFAIK R/3

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
 
Not the answer you were looking for? Post your question . . .
196,931 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,931 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors