Fastest way to delete all records?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Fastest way to delete all records?

Post by kneighbour » Thu 21 Dec 2017 00:02

I have a few tables that I use for temporary functions, and they can get very big - like 2.6 million records in my latest project. I need to delete these all the time, and it is very slow. It almost takes longer than filling them!

I am currently setting up a UniQuery and running SQL like 'DELETE FROM TEMPTABLE'.

Is there a faster way to do it? I am thinking of Dropping the table and then recreating it again. But before I do that, are there any functions in UniDac that might help? The Batch delete option does not seem much use as I simply want to delete everything and I don't have a primary key that I know the value of to setup any parameters with.

kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Re: Fastest way to delete all records?

Post by kneighbour » Thu 21 Dec 2017 02:37

Never mind - I found that I can use the UniTable and then EmptyTable. That is very fast. Seems the best way when I want to delete everything.

ertank
Posts: 172
Joined: Wed 13 Jan 2016 16:00

Re: Fastest way to delete all records?

Post by ertank » Thu 21 Dec 2017 08:44

I do not know code written for EmptyTable. But, SQL command "truncate" should be the fastest method among different database systems as to my knowledge.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Fastest way to delete all records?

Post by MaximG » Fri 22 Dec 2017 05:31

The described functionality depends on the used DB and does not depend on access components behavior, which you are using. When using the EmptyTable method, UniDAC automatically composes a query as follows DELETE FROM ... or TRUNCATE ... depending on the used provider

Post Reply