Solved

Why does DELETE take a long time (and act so differently) when table has over 200 fields)?

Posted on 2009-05-13
7
573 Views
Last Modified: 2012-05-06
Dear Experts,

I have a perplexing problem that has confounded many at our company.  I was hoping someone
here had the answer.

I have few tables that are related to a master table.
The master table has a key seq number which is related to a number of different tables.
When I want to delete from the master and related tables the delete takes a very long time
for the tables with 200+ fields.
In Query Analyzer, I noticed that when I enter the following command

DELETE FROM DetailTable where SeqNum in (10355)
I get the following response:
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
...
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)

with (0 row(s) affected) appearing up  to the number of fields in that table.
And this takes about 20 seconds to complete

If I execute the same command on a much smaller table (about 20 fields)
DELETE FROM DetailTable_2 where SeqNum in (10355)
I simply get the response
(0 row(s) affected)
within a fraction of a second.

Each table has SeqNum indexed.  So I don't know if this is a bug in SQL server, or if
there is something else that needs to be done for such a large table.

We don't have  a cascade update or delete on the table.  I know we may be able to add this,
but before I did, I thought I'd ask because adding a cascade delete may affect legacy code (which I'm trying to avoid).  I also don't want to redesign the table (into many smaller tables), again because of legacy code.

Thank you all in advance for your help!
0
Comment
Question by:BrianMc1958
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 450 total points
ID: 24379770
that "larger" table has for sure a trigger on it.
you might want to "disable" that trigger for your large delete ...
0
 

Author Comment

by:BrianMc1958
ID: 24379838
Yes,
You are right, I removed the trigger and it took a fraction of a second.  Of course, we want to trace
when people delete records from our database as a matter of policy.  Is there another way to handle
this situation?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24380709
>>Is there another way to handle this situation?<<
Don't allow it?

Or so it does not sound facetious, only allow DELETEs (as well as UPDATEs and INSERTs) from Stored Procedures which can only be run by users that have the appropriate EXECUTE permissions.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 60

Assisted Solution

by:chapmandew
chapmandew earned 50 total points
ID: 24380833
One idea is to setup replication and do the auditing on the subscriber...
0
 

Author Comment

by:BrianMc1958
ID: 24381183
Thank you all for your comments.
I do have a bit of trouble understanding why a trigger would cause such a huge problem.   I've
noticed in other large tables (that we have audit triggers on), the amount of time to execute is
doubled (not 20X as long in this instance).  I've notice that even if no records are deleted in
my query, it still takes an inordinate amount of time.

0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24382440
the trigger is sql also, so all the sql statements in there take also some time.
you have to check if any of those queries are not optimized.

the suggestion of chapmandew is usually the best method, offloading the trigger to a dedicated server...
0
 

Author Closing Comment

by:BrianMc1958
ID: 31581220
Thank you all for your help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question