AVCXClasses()

Create Database, Delete Database

These commands create and destroy databases, respectively. A database is a collection of tables, views, connections and other stuff. See "DBC, DBF, FPT, CDX—Hike!" for more on what constitutes a database in Visual FoxPro.

Usage

CREATE DATABASE [ Name | ? ]
If you omit Name, whether or not you include the "?", the Open dialog appears with a default name of DATAn.DBC, where n is the number of times you've used the Open dialog to name a new database in this session. It doesn't matter whether or not you assign a name other than the default. If you use the Open dialog, the counter on the end goes up. Try this:

CREATE DATABASE ? * Change the name to Fred and choose OK CREATE DATABASE ? * Note that new database name offered is DATA2.DBC
Weird, but it doesn't really matter, since you'd never want to use the default name.

Creating a database opens it (exclusively). Unlike tables, databases don't use anything like work areas, so opening one doesn't close any others that are already open. However, only one database can be current at a time. The newly created database is empty and becomes the current database. You have to use commands or the Database Designer to put stuff in it.

When a database is open and current, creating a new table automatically puts it in the open database.

Be careful about database names. Because the database is stored as a file, you get only as many characters as the Windows version allows. Using VFP 3 in Windows 3.1, you can CREATE DATABASE AVeryLongName, but it's stored as AVeryLon.DBC.

Example

CREATE DATABASE MyImportantData

Usage

DELETE DATABASE Name | ? [ DELETETABLES ] [ RECYCLE ]
DELETE DATABASE is the right way to get rid of a database. It does all the necessary cleanup, including freeing all the tables in the database. Deleting the DBC, DCT and DCX files any other way orphans the tables in the database, which leaves them unusable until you issue the FREE TABLE command.

Unlike CREATE DATABASE, you must specify either a name or the ? with DELETE DATABASE. The ? brings up the Open dialog to choose a database to delete, bizarre as that sounds. (In fact, despite its title, the Open dialog is the one that has the right functionality.)

Specifying DELETETABLES means that Visual FoxPro should delete all the tables in the database along with the database itself. This is pretty drastic, but can be handy when working with test data.

Add the RECYCLE keyword to send the database files to the purgatory of the Windows Recycle Bin. Without it, they're gone, gone, gone.

Not surprisingly, restoration of a database from the Recycle Bin doesn't work very well. When you open the restored database, it appears to contain what it did before, but the tables still think they're free tables, if you specified not to delete them as well. You have to let VFP correct the backlinks before the database works right.


A database must be closed in order to delete it.

DELETE DATABASE respects the setting of SAFETY.

See Also

Add Table, Close Database, Create, Create SQL View, Create Table, DBGetProp(), DBSetProp(), Modify Database, Open Database, Pack Database, Set Database, Set Safety, Validate Database


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net