Solved

The need to compact Access database

Posted on 2010-11-11
4
445 Views
Last Modified: 2012-05-10
I have simple JET database in my application: one table, 9 text columns with limited width, indexed by first column [ID] - see code. This table is accessed using connection string like "'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MyData.mdb;Persist Security Info=False" (more specifically I'm using Delphi 6 and TADOTable/TADOQuery). From time to time the content is to be replaced by external data (approximatively 13000 records in .csv file, 500 kb size). The way I'm doing it:

for every record read from .csv
  try
    INSERT   // this produces an error if ID exists
  except
     UPDATE
   end

And now the problem.
My database is about 1Mb. After content replacing it grows to 250Mb. When I compact it then it is back to 1MB. I can use algorithm like

if record exists then UPDATE else INSERT

and then database size is stable, but it is a 100 times slower.
Is it normal behaviour or I'm doing something wrong?. The program is designed to be run on various machines and sometimes this extra 250Mb can be a problem.
The enviroment is Delphi 6, Win XP SP3, Access 2010 installed.
CREATE TABLE [players] (

  [ID] TEXT(5) NOT NULL DEFAULT '00000',

  [IMIE] TEXT(20) NOT NULL,

  [NAZWISKO] TEXT(30) NOT NULL,

  [WK] TEXT(4),

  [OKREG] TEXT(3),

  [INFO] TEXT(2),

  [KLUB] TEXT(50),

  [ZNIZKA] TEXT(1),

  [SKLADKA] TEXT(1),

PRIMARY KEY ([ID])

Open in new window

0
Comment
Question by:jfromanski
4 Comments
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 100 total points
ID: 34112145
Checking whether the record exists is the way to do it and I'm assuming you are only checking using the primary key. It will definitely slow the import process but is much better than trying to insert then getting an error and then updating.

100 times slower is a little bit too much, I'm not sure how to re-index an Access database but it may be a worthwhile topic for you to do some research on
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 100 total points
ID: 34115195
Yes, optimizing your indexes would be you first step.

FWIW, I know 250Mb seems like a lot, but this may very well be what Access needs to make it.
In today's world of Terabyte Hard drives, 250mb is minuscule...
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Access MVP) earned 300 total points
ID: 34115620
"Is it normal behaviour or I'm doing something wrong?."
Pretty much normal behavior. Append records and even just updating records causes bloating. It's a fact of mdb life.  Compact & Repair does re-indexing, among other things, such as actually removing any objects that may have been deleted, records that may have been deleted and more.  In fact, it's the best preventative maintenance you can do on an Access database.

"indexed by first column [ID]"
So, you only have one index. Adding more indexes will slow down the appending process, because JET has to re-index for each record added.

"sometimes this extra 250Mb can be a problem."
How so.

Overall, I'm not really seeing a problem.

mx
0
 
LVL 10

Author Closing Comment

by:jfromanski
ID: 34120734
Thanks for comments. So I will switch back to MySQL - not so easy to use and needs additional installs. BTW: I've asked this question becouse of several user's complains - all using in their clubs old Win98 desktops with 50 or 100 Mb HD
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now