SQL Server Performance Forum – Threads Archive
Speed Issues with Delete Query
i have this stored procedure that deletes details of a person.It takes ages to complete.I cannot disable triggers/Constraints as this will affect other users.Any help on how to speed it up.
You could delete in smaller batches. But if you need to delete large amounts of data, probably you can schedule this for off-peak hours where none or only few users are in the database. —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)
There is no generic solution to speed up normal data manipulation actions. On the other hand, if we could have a look at the stored procedure … How often does the sproc get executed?
Does it always take this long? Also we need to know about the indexes on the table from which you’re deleting.
Hai Am also a starting member.I know i may be also going to ask some qustions like this n the coming day.. In this case please include the table constraints(including Priimary key if u have one.)and also ur proc.. to get a clear idea..if ur deleting all the data from a temp table if not need to be logged then use truncate table instead of deleted
Good point, <s>Mirko</s> <b>Adriaan</b>! [<img src=’/community/emoticons/emotion-1.gif’ alt=’

Frank, have you mixed threads or you gave me the credit for Adriaan’s post? [<img src=’/community/emoticons/emotion-1.gif’ alt=’

Bummer! I seem to have mixed things up! [<img src=’/community/emoticons/emotion-1.gif’ alt=’


Below is a sample code.It Repeats same code in several tables.Frank what do u mean by delete in smaller batches?.
—————————-
delete from table_1 where id= @id
set @@error_value = @@error
if ( @@error_value <> 0 )
begin
rollback tran
return 1
end
Something like this
SET ROWCOUNT 5000
DELETE FROM table WHERE condition
—
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)
Frank, you should add a nice WHILE loop to that.[<img src=’/community/emoticons/emotion-1.gif’ alt=’

Aargh, that’s not my day today. [xx(] —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs
Ich unterstuetze PASS Deutschland e.V. http://www.sqlpass.de)
]]>