Page 1 of 1

Fastest way to delete all records?

Posted: Thu 21 Dec 2017 00:02
by kneighbour
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.

Re: Fastest way to delete all records?

Posted: Thu 21 Dec 2017 02:37
by kneighbour
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.

Re: Fastest way to delete all records?

Posted: Thu 21 Dec 2017 08:44
by ertank
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.

Re: Fastest way to delete all records?

Posted: Fri 22 Dec 2017 05:31
by MaximG
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