|
-
Feb 2nd, 2018, 06:12 AM
#1
Thread Starter
Junior Member
Deleting selected records from a large database table
I'm looking for some thoughts or explanation of the following.
I need to delete a number of records of a specific type from a very big table (many thousands of records)
I thought the most obvious method would be:
Dbs.Execute "DELETE FROM " & tblAcronym & " WHERE " & acrSOURCE & " = '" & sRecordType & "'"
And this works fine, but takes it about 2 minutes, leaving the user to watch a "spinning cursor".
So then I tried this method (which I expected to be slower):
Create a selected Dynaset, then just delete all its records (which also deletes then from the underlying table).
With Dbs.CreateQueryDef(vbNullString, "SELECT * FROM " & tblAcronym & " WHERE " & acrSOURCE & " = '" & sRecordType & "'").OpenRecordset(dbOpenDynaset)
Do While Not .EOF
.Delete
.MoveNext
Loop
.Close
End With
Surprisingly, this only took about 30 seconds and works fine, and I am wondering why the Dbs.Execute was so much slower?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|