Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete a milion of records ado + vb6

Status
Not open for further replies.

sal0003

Programmer
Apr 5, 2010
22
0
0
IT
I use the tipical ado jet con and vb6 code.
I have an access table with approx 4.500.000 records in 43 fields.
All field are filled with value.
I use the delete * from table ecc.... but sure the code is very very slow...
Suggestion please to make a fast way to delete.
tks.
 
Can you drop the table and recreate it. It would execute a lot faster.
 
please i'm a new bie....
example code?
tks
 
in other case the drop option is reserved for Sql Server or not?
 
We have a Access application that we have used for years where we drop a table and re-create it (it is done weekly).

Example:
DoCmd.RunSQL "Drop TABLE tblBatchInfo"

DoCmd.RunSQL "CREATE TABLE tblBatchInfo(BatchNumber integer, BatchDate datetime,LastChkNum integer)"

The above code drops tabel tblBatchInfo, then re-creates the table with the fields, BatchNumber, BatchDate, and LastChkNum.

I hope this helps.
 
The TRUNCATE command can only be used on SQL Server and not Access, but the DROP command can most definitely be used in Access.

If there were a way to use the TRUNCATE command in Access, you'd be in business for sure! That is one super-fast command - faster than dropping and recreating by far!
 
Here's what I'd use for the full code in that section, so you don't get a lot of prompts:

Code:
DoCmd.SetWarnings False
DoCmd.RunSQL "DROP TABLE [blue]MyTableName[/blue]"
DoCmd.RunSQL "CREATE TABLE [blue]MyTableName[/blue](FieldID integer, FieldDate datetime, FieldOther text)"
DoCmd.SetWarnings True

Basically it's the same as what was already suggested, but just adding in the setwarnings statements.

Also, if you've got a large number of fields in said table, then I'd suggest creating the SQL statement ahead of time as a string, and then running that string.... for creating the table.. so something like:

Code:
Dim strSQL as String
strSQL = "CREATE TABLE MyTableName(Field1 Integer ,Field2 Text ,Field3 Date, Field4 Date ,Field5 Integer)"

DoCmd.SetWarnings False
DoCmd.RunSQL "DROP TABLE MyTable"
DoCmd.RunSQL strSQL
DoCmd.SetWarnings True

Anyway, that should get you going..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top