Solved

The need to compact Access database

Posted on 2010-11-11
4
450 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya 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 - Microsoft MVP, Access and Data Platform) 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

617 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