Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete query - taking long time to complete

Status
Not open for further replies.

TimGoff

Technical User
Jul 16, 2002
166
GB
Hi

The following SQL takes an exceptionally long time to run (over 15 mins) - and is only deleting 500 rows. Has anyone any thoughts on how to improve it, or an alternative way of doing it?

strSQLString = "DELETE * FROM tbl_Bcst_T_srs WHERE tbl_Bcst_T_srs.Series_ID NOT IN (Select series_id from tbl_Bcst_T_prg)"

gcnnDB.Execute strSQLString, lngRecordsDeleted, adCmdText

Thanks in advance
Tim
 
A few thoughts which might be of some use ...

1. Is Series_Id indexed in both tables?
2. Is Series_Id the same data type (e.g. integer) in both tables?
3. Does the process run any faster (or slower) if you run it via DoCmd.RunSQL?
4. What happens if you use a two-step process like this:

-- Assume tbl_Bcst_T_srs has an extra True/False field added, called DeleteFlag
-- Run an update query to set the flag to True, for records where Series_ID IS in tbl_Bcst_T_prg
-- Run a delete query, to delete records from tbl_Bcst_T_srs where the flag is 'False'

Maybe trying these ideas will give a clue about what is happening, and improve performance.

Bob Stubbs (London, UK)
 
Another thing to try, is using a stored query in stead of dynamic sql, also adding the adexecutenorecords might help.

[tt]gcnnDB.Execute strSQLString, lngRecordsDeleted, adCmdText+adexecutenorecords

gcnnDB.Execute "queryname", lngRecordsDeleted, adcmdstoredproc+adexecutenorecords[/tt]

Roy-Vidar
 
Typed, not tested:
strSQLString = "DELETE S.* FROM tbl_Bcst_T_srs AS S LEFT JOIN tbl_Bcst_T_prg AS P ON S.Series_ID = P.series_id WHERE P.series_id Is Null"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for all your posts guys..haven't had time to test them all yet, appreciate your comments
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top