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

The examples were created with SQL Server 2008. SQL Server 2005 does not support MERGE. It is available only with SQL Server 2008

You can download SQL server 2008 (KATMAI) at https://connect.microsoft.com/SQLServer/content/content.aspx?ContentID=5395



.
steve dassin
steve dassin
SSC-Enthusiastic
SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)

Group: General Forum Members
Points: 176 Visits: 2077

Jacob, Wayne, Charles and other interested parties,

There is the sql standard and then there is the 'relational' approach. I urge you to compare S2008 MATCH with the ideas presented here:

http://beyondsql.blogspot.com/2007/06/dataphor-intelligent-views.html

We should be talking about intelligient operations on 'views'. And views are something sql has...well dumbed down

MATCH, conceptually, has much in common with the S2008 idea of a table parameter. I'm trying to show these concepts in a mature form now, as opposed to the MS siblings of pre-adolescence

www.beyondsql.blogspot.com

I hope to be presenting at the Phoenix SQL Server User Group soon. I will try to make things lively and informative


Jake
Jake
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 423
Has anyone compared the performance of a MERGE statement with the "old" standard of UPDATE and INSERT? Specifically with regards to data warehouse loading.

Thanks,

jake



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, it's faster. It doesn't need to loop through the data multiple times to find out which rows exist and therefore need updating, and which ones don't and therefore need inserting.

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

Group: General Forum Members
Points: 1 Visits: 5
How can I accomplish the same result albeit slower in SQL Server 2005 - not using MERGE?
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
In SQL Server 2005, you would need three separate DELETE, UPDATE and INSERT statements. You can find an example (look at the last example) here: http://www.sqlservercentral.com/columnists/jSebastian/2912.asp

.
rajeev_2004_3
rajeev_2004_3
Grasshopper
Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)Grasshopper (10 reputation)

Group: General Forum Members
Points: 10 Visits: 116
Hi Sebastian,

On going thru your code, i could notice that you are delete the records by ...WHEN SOURCE NOT MATCHED THEN DELETE;

i suppose that it would delete all other records which doesn't meet the on clause join condition of the merge, like orderdetails of other orders ..........

Pls. clarify me...
adhiman
adhiman
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 152
I was working with SQL 2008 R2 and found that to use delete when there is no match, the syntax got changed.
Instead of

"WHEN SOURCE NOT MATCHED THEN
DELETE;"


It is now

"WHEN NOT MATCHED BY SOURCE
THEN DELETE;"



Hope you guys have noticed. But Just an FYI
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