473,473 Members | 2,253 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Delete vs. Merge

I need to delete some rows from a table. The rows to delete are
uniquely identified in a second table. I realize that I have two
options here:

1) DELETE FROM tableA WHERE ...

2) MERGE INTO tableA ... USING tableB ... ON .... WHEN MATCHED DELETE
....

I was wondering which of the two options would provide best performance
overall. I would welcome any suggestions.

Thanks!

Nov 12 '05 #1
1 5113
de*******@yahoo.com wrote:
I need to delete some rows from a table. The rows to delete are
uniquely identified in a second table. I realize that I have two
options here:

1) DELETE FROM tableA WHERE ...

2) MERGE INTO tableA ... USING tableB ... ON .... WHEN MATCHED DELETE
...

I was wondering which of the two options would provide best performance
overall. I would welcome any suggestions.

Thanks!

On average I would expect DELETE to be faster.
The reason is that MERGE has to raise an error if it tried to delete the
same row twice. This is extra work.
DELETE FROM T WHERE EXISTS(SELECT 1 FROM S WHERE T.c1 = S.c1)
Doesn't care wether S.c1 is unique.
If S.c1 and T.c1 are both keys MERGE may get up to the same speed
depedending on your fixpack.
MERGE can't be faster though :-)

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: cfxchange | last post by:
I am looking into work-arounds for what seems to be a flaw, or "undocumented feature" of SQL Server replication and Instead of Delete triggers not playing together. It seems that if you want to...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
0
by: Clay Luther | last post by:
Again, we have an odd performance problem with PGSQL, 7.4b2. Here is the query: delete from numplan where pkid in (select numplan.pkid from numplan left outer join pilothuntgroup on...
2
by: Aaron | last post by:
hello, i am perfoming a mail merge with the following code. Public Function MergeIt() Dim objWord As Object Set objWord = GetObject("C:\MyMerge.doc", "Word.Document") ' Make Word visible....
8
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
4
by: John J. Hughes II | last post by:
Could someone explain how to merge the form menu with the mdi container window. The menu strip items on the form window merge but I either end up with a blank blue menu on the form or top list of...
4
by: pike | last post by:
8.1 FP11 on AIX 5.3. The following DELETE is poorly performing and causing lock escalation (and subsequent deadlock time-outs): DELETE FROM submission_log WHERE subm_id = ? OR subm_id =...
4
by: news.onet.pl | last post by:
Hi!! Is it possible to delete (or update) with join ?? For example DELETE a FROM TableA a INNER JOIN TableB b ON b.id = a.bId
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.