How do I insert 800000 records into an MS Access table?

前端 未结 16 999
故里飘歌
故里飘歌 2020-12-17 04:13

I need to insert 800000 records into an MS Access table. I am using Delphi 2007 and the TAdoXxxx components. The table contains some integer fields, one float f

相关标签:
16条回答
  • 2020-12-17 04:55

    How fast is your disk turning? If it's 7200RPM, then 800,000 rows in 3 minutes is still 37 rows per disk revolution. I don't think you're going to do much better than that.

    Meanwhile, if the goal is to streamline the process, how about a table link?

    You say you can't access the source database via ADO. Can you set up a table link in MS Access to a table or view in the source database? Then a simple append query from the table link would copy the data over from the source database to the target database for you. I'm not sure, but I think this would be pretty fast.

    If you can't set up a table link until runtime, maybe you could build the table link programatically via ADO, then build the append query programatically, then invoke the append query.

    0 讨论(0)
  • 2020-12-17 04:55

    HI The best way is Bulk Insert from txt File as they said you should insert your record's in txt file then bulk insert the txt file into table that time should be less than 3 second.

    0 讨论(0)
  • 2020-12-17 04:56

    I would replace MS Access with another database, and for your situation I see Sqlite is the best choice, it doesn't require any installation into client machine, and it's very fast database and one of the best embedded database solution.

    You can use it in Delphi in two ways:

    1. You can download the Database engine Dll from Sqlite website and use Free Delphi component to access it like Delphi SQLite components or SQLite4Delphi

    2. Use DISQLite3 which have the engine built in, and you don't have to distribute the dll with your application, they have a free version ;-)

    if you still need to use MS Access, try to use TAdoCommand with SQL Insert statment directly instead of using TADOTable, that should be faster than using TADOTable.Append;

    0 讨论(0)
  • 2020-12-17 04:56

    Perhaps you could open a ADO Recordset to the table with lock mode adLockBatchOptimistic and CursorLocation adUseClient, write all the data to the recordset, then do a batch update (rs.UpdateBatch).

    0 讨论(0)
提交回复
热议问题