Home Forums SQL Server 7,2000 T-SQL Stored procedure performance improvement RE: Stored procedure performance improvement

  • 1) Are you running the stored proc in a transaction, as you mentioned you want to be able to rollback. If you do SQL Server will be very slow deleting a large number of records, and will keep locking more and more of the tables as it deletes. There are some strategies for getting around this (without running large deletes in a transaction), such as using an IsDeleted column, moving records to a Deleted Table - but if it goes wrong, you need code to recover, as obviously you won't have rollback as an option.

    2) are there any triggers on any of the tables you delete from? these could also slow down your code.

    3) look for some optimisations.

    It looks like your using WHERE TRANS_ID IN

    (SELECT TRANS_ID FROM TRANS

    WHERE SCHEDULED = 1 AND ALLOWED = 1 AND PRACTICE_MODE = @boolean1) in a number of places. Perhaps select those TRANS_IDs into a #Tmp table, index it on Trans_ID and join the #tmp to the table you're deleting from instead of accessing the TRANS table for every delete.

    4) are users accessing the tables at the time you run the delete, or do you run it in a maintenance time?