SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Assist me the merge statement performance in sql server..


Assist me the merge statement performance in sql server..

Author
Message
vignesh.ms
vignesh.ms
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 516
Hi Everybody,

Im using following query, is there any other alternative way?


MERGE DistinctData AS TARGET
USING DataTable AS SOURCE
ON (TARGET.msisdn = SOURCE.Charged_party_number)
WHEN NOT MATCHED BY TARGET THEN
INSERT (msisdn)
VALUES (SOURCE.Charged_party_number);


Assist me the merge statement performance in sql server..
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26058 Visits: 17531
vignesh.ms (8/26/2013)
Hi Everybody,

Im using following query, is there any other alternative way?


MERGE DistinctData AS TARGET
USING DataTable AS SOURCE
ON (TARGET.msisdn = SOURCE.Charged_party_number)
WHEN NOT MATCHED BY TARGET THEN
INSERT (msisdn)
VALUES (SOURCE.Charged_party_number);


Assist me the merge statement performance in sql server..


I am guessing by the topic that the performance of this is not acceptable? Without more details it is impossible to offer much help. Please see this article for best practices when seeking help on performance issues. http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
vignesh.ms
vignesh.ms
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 516
hi SSCrazy Eights,

I have 2 table say source and destination.

I'm trying to insert data from source table to destination table ,which are not available in the destination table.

this is the requirement, suggest me the best possible way.

Thanks many..
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26058 Visits: 17531
vignesh.ms (8/26/2013)
hi SSCrazy Eights,

I have 2 table say source and destination.

I'm trying to insert data from source table to destination table ,which are not available in the destination table.

this is the requirement, suggest me the best possible way.

Thanks many..


Your description is not very clear. It sounds like a good candidate for the MERGE statement (which you said you used in your original post).

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
vignesh.ms
vignesh.ms
Old Hand
Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)Old Hand (366 reputation)

Group: General Forum Members
Points: 366 Visits: 516
Sean Lange (8/27/2013)
vignesh.ms (8/26/2013)
hi SSCrazy Eights,

I have 2 table say source and destination.

I'm trying to insert data from source table to destination table ,which are not available in the destination table.

this is the requirement, suggest me the best possible way.

Thanks many..


Your description is not very clear. It sounds like a good candidate for the MERGE statement (which you said you used in your original post).



Hi Sean Lange,

Forgot about the query and all that I have shared already...




create table SourceTable
(number int)

create table DestinationTable
(number int)

insert into SourceTable values(1)
insert into SourceTable values(2)
insert into SourceTable values(3)
insert into SourceTable values(4)
insert into SourceTable values(5)
insert into SourceTable values(6)


insert into DestinationTable values(1)
insert into DestinationTable values(2)
insert into DestinationTable values(3)


In the above sample, sourcetable contain values 1,2,3,4,5,6
And Destinationtable contains 1,2,3

I need a query to insert 4,5,6 alone from source table .

(ie) query should check whether the upcoming data is already there or not. if not insert else skip.

note : both tables are too huge. please suggest me best way to achieve the goal

hope now you could understand my requirement.

Thanks
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)One Orange Chip (26K reputation)

Group: General Forum Members
Points: 26058 Visits: 17531
That helps clarify. I wouldn't use MERGE for this. I converted your sample ddl into temp tables so it is easier to work with in a test database.


create table #SourceTable
(number int)

create table #DestinationTable
(number int)

insert into #SourceTable values(1)
insert into #SourceTable values(2)
insert into #SourceTable values(3)
insert into #SourceTable values(4)
insert into #SourceTable values(5)
insert into #SourceTable values(6)

insert into #DestinationTable values(1)
insert into #DestinationTable values(2)
insert into #DestinationTable values(3)

select *
from #SourceTable
where number not in
(
select number
from #DestinationTable
)



_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
RandomEvent
RandomEvent
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 404
Well worth a read when optimising for large datasets

http://technet.microsoft.com/en-us/library/cc879317(v=sql.105).aspx
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