July 17, 2007 at 11:42 am
Comments posted here are about the content posted at http://www.sqlservercentral.com/columnists/jSebastian/3122.asp
.
September 10, 2007 at 9:19 pm
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://blogs.lobsterpot.com.au
September 10, 2007 at 9:22 pm
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
September 10, 2007 at 9:38 pm
Yes Leo, that's correct.
Rob Farley
LobsterPot Solutions & Adelaide SQL Server User Group
Company: http://www.lobsterpot.com.au
Blog: http://blogs.lobsterpot.com.au
September 11, 2007 at 12:32 am
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
September 11, 2007 at 1:33 am
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
.
September 11, 2007 at 1:38 am
Agreed with you, Leo.
.
September 11, 2007 at 7:23 am
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.
September 11, 2007 at 7:56 am
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
September 11, 2007 at 8:38 am
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
September 11, 2007 at 8:39 am
Great example, and thanks for the info on the MERGE functionality. A question about usage...
With this syntax:
WHEN SOURCE NOT MATCHED THEN
DELETE
Can I put other things in there instead of "DELETE"? I don't physically delete from my databases - we use a logical delete using an InactiveDate field. Is there a way to set that InactiveDate field for those records that are in the source but not matched with any data in the XML (and therefore need to be "deleted")?
Thanks.
September 11, 2007 at 9:20 am
What triggers get fired with Merge ? If it's more then one trigger, is there a fixed order or can they be fired in a random order ?
Thanks,
Don
September 11, 2007 at 9:39 am
Here is an example:
WHEN
SOURCE NOT MATCHED THEN
--DELETE
UPDATE SET
d
.Deleted = 1
The above code updates the status of the column "deleted" to 1, instead of physically deleting the record.
If you are doing this, you need another change at the JOIN condition, to skip the deleted records.
USING
OrderInfo AS o
ON
(d.OrderNumber = o.OrderNumber AND d.ItemNumber = o.ItemNumber AND d.Deleted = 0)
.
September 11, 2007 at 9:46 am
Cool. Then how do you undeleted a deleted record?
ATBCharles Kincaid
September 11, 2007 at 9:50 am
From my testing, i found that the triggers are always fired in the following order.
1. insert
2. update
3. delete
I am not sure if we can always assume this order.
.
Viewing 15 posts - 1 through 15 (of 27 total)
You must be logged in to reply to this topic. Login to reply