简体   繁体   中英

VBA/ACCESS: How to quickly delete plenty records from table?

I desperately try to delete a huge amount of records from a table in an access database (*.accdb) within an acceptable time.

More specific: I have a collection of integer IDs (ca. 50.000) whose corresponding records are supposed to be deleted from a table (ca. 300.000 rows).

Using a "for each x in collection" + "db.execute(SQL delete command)" approach takes ages.

Is there any other solution I could try?

Many thanks in advance and regards, Sebastian

Use something like DELETE FROM table WHERE id IN (...) and fill the set for the IN part as appropriate, eg id IN (5, 6, 12) .

Edit: for practical reasons, you could limit the amount of IDs in the IN set to, say, 1000. This would still reduce your number of queries by a large factor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM