Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


The Power of Merge


The Power of Merge

Author
Message
jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523
Comments posted here are about the content posted at http://www.sqlservercentral.com/columnists/jSebastian/3122.asp

.
Rob Farley
Rob Farley
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 375
But why use XML to pass data in, when SQL2008 gives you Table-Value Parameters?

(I do love Merge - I spoke on it last month at the UG I run, and I'll be presenting on it in the next few months at other user-groups and at a code-camp too).

Rob Farley
LobsterPot Solutions & Adelaide SQL Server User Group
Company: http://www.lobsterpot.com.au
Blog: http://sqlblog.com/blogs/rob_farley
Leo Miller
Leo Miller
Grasshopper
Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)Grasshopper (13 reputation)

Group: General Forum Members
Points: 13 Visits: 20

Surely the set d.ItemNumber = o.ItemNumber isn't needed as the "join" is on OrderNumber and ItemNumber:

MERGE OrderDetails AS d

   48 USING OrderInfo AS o

   49 ON (d.OrderNumber = o.OrderNumber AND d.ItemNumber = o.ItemNumber)

WHEN MATCHED THEN

   51     UPDATE SET

   52         d.ItemNumber = o.ItemNumber,

 

Regards

 

Leo


Rob Farley
Rob Farley
SSC-Enthusiastic
SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)SSC-Enthusiastic (166 reputation)

Group: General Forum Members
Points: 166 Visits: 375
Yes Leo, that's correct.

Rob Farley
LobsterPot Solutions & Adelaide SQL Server User Group
Company: http://www.lobsterpot.com.au
Blog: http://sqlblog.com/blogs/rob_farley
martial wilbert
martial wilbert
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
Points: 2 Visits: 7

Hi,

Effectively, it seems really easy to use it. But what about performances? Is there any difference between using MERGE and using 'old' code ?

And what about MERGE and global SQL specifications? Is there a chance to have this keyword appears on the next sql language norm?

Anyway, thanks for this article. I'm impatient to install this new version to play with it

Have a nice day

 

PS: ALL WITH ME BEHIND FRENCH RUGBY TEAM (They need it :blush


jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523

Hi Rob,

The focus of this article was to present the MERGE keyword and hence I started from where we stopped in a previous article.

There is another article scheduled, which introduces the table-value parameter and will be out in the next few days.

thanks

Jacob



.
jacob sebastian
jacob sebastian
SSC-Addicted
SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)SSC-Addicted (472 reputation)

Group: General Forum Members
Points: 472 Visits: 2523
Agreed with you, Leo.

.
Andy Warren
Andy Warren
SSCertifiable
SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)SSCertifiable (7.2K reputation)

Group: Moderators
Points: 7221 Visits: 2679

Im familiar with the scenario, but Im not sure I'm sold yet that this is substantially better - one more syntax with quirks you have to learn! Performance could be a key point, I look forward to seeing how it performs.



Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
noeld
noeld
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6320 Visits: 2048
Merge has been present in DB2 for years, it is a good thing that MS is catching up. Personally I find it handy for cetain things but I am afraid that this can be used on situations where a better application design is the key.

Thanks for the article. Simple and to the point.


* Noel
Charles Kincaid
Charles Kincaid
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1041 Visits: 2383

What about REPLACE INTO?  That would be easier on the coders.  The way it's supposed to work is that if the primary key does not exists the row gets inserted.  If the row does exist it gets replaced.  There was some talk that rows affected would come ack as 1 if the insert happened and 2 if the row was replaced.  The thinking being that the replace was like a delete and an insert.

If I'm going to have to code procedures then I'll just code the procedures.  There is only one possible benefit from doing things the MERGE way.  I can update an existing order in my order table but new orders could get put into a new_order table.  Why you would want to do that I don't know.

I was jumping up and down happy when I read the article headline and then so dissapointed when I saw the syntax.



ATBCharles Kincaid
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search