Pack Database

Unlike its table-oriented counterpart, PACK, this command is actually useful. Information about a database is stored in an ordinary FoxPro table (well, okay, actually a Visual FoxPro table) with a special extension. Various operations on a database can leave deleted records behind. PACK DATABASE cleans up the deleted records, leaving the DBC file smaller and more manageable. In addition, starting in VFP 6, the Referential Integrity Builder requires that the database is free of deleted records, so you'll need to use this command if you want to generate RI code for your database.

Usage

PACK DATABASE
PACK DATABASE does for a DBC what PACK does for a DBF. The difference is that there are other (read: safer) ways to perform the same function on a DBF. When you PACK DATABASE, FoxPro not only throws away the garbage, it also reorganizes what remains. In particular, each record in a DBC has a unique object ID (cleverly named "objectid") always equal to the physical record number; PACK DATABASE reassigns the object IDs to keep them matching the record numbers.To our pleasant surprise, opening the DBC with USE and issuing PACK also updates the objectid field. However, using COPY TO for a "safe PACK", of course, doesn't update the object IDs and results in a table that's not recognized by FoxPro as a database.Our take: Always make a backup and then use PACK DATABASE if you need it, and don't risk destroying your database. Which isn't to say that there aren't times to open the DBC as a table and muck around—this just isn't one of them. Be aware that PACK DATABASE has the same risks as PACK. It's just that there isn't another easy way to get the job done. Be sure to back up your database before you pack if you care about keeping it intact.The database must be opened EXCLUSIVE in order to pack it.In VFP 7, if the database has database events turned on, the PackData event fires.

PACK DATABASE collapses all nodes in all TreeViews in the Project Manager windows of all open projects, even if the database being packed isn't included in the project.


See Also

Close Database, Modify Database, Open Database, Pack, PackData, Remove Table, Validate Database


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .