I need to insert 800,000 records into an MS Access table. I am using Delphi 2007 and TAdoXxxx components. The table contains some integer fields, one floating point field and one text field with one character. There is a primary key in one of the integer fields (which is not auto-synchronizing) and two indices for the other integer and the float field.
Inserting data using AdoTable.AppendRecord(...) takes> 10 minutes, which is unacceptable, since this is done every time the user starts using a new database with the program. I canโt pre-populate the table because the data comes from another database (which is not available through ADO ).
I managed to get down for about 1 minute by writing to a tab-separated text file and using the tAdoCommand object to execute
insert into table (...) select * from [filename.txt] in "c:\somedir" "Text;HDR=Yes"
But I don't like the overhead.
There must be a better way, I think.
EDIT:
Additional Information:
- MS Access was chosen because it does not need additional installation on the target machine (s), and the entire database is contained in a single file that can be easily copied.
- This is a single user application.
- Data will be inserted only once and will not change throughout the life of the database. Although the table contains one additional field, which is used as a flag to indicate that the corresponding record in another database has been processed by the user.
- One minute is acceptable (it will also be up to 3 minutes), and my solution works, but it seems to me too complicated, so I thought that there should be an easier way to do this.
- After the data has been inserted, the performance of the table is pretty good.
- When I started planning / implementing the function of the program working with the Access database, the table was not required. This became necessary later when the client requested another function. (Isn't that always the case?)
EDIT:
Of all the answers I have received so far, it seems that I already have the fastest way to insert so much data into the Access table. Thanks to everyone, I appreciate your help.
source share