Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Create, MODIFY STRUCTURE

These two commands are for interactively creating and modifying tables. Although they can be used in programs, you’d rarely want to do so since they bring up the Table Designer. You probably don’t want to give an application’s users access to that dialog.

Usage

CREATE [ cTableName | ? ]

Omitting the table parameter is the same as passing the “?”; both bring up the Save As dialog (customized to the CREATE command) to let you specify a name for the new table. Once a table name has been specified, the Table Designer appears. In VFP 7, if a database is selected and Database Events are turned on, the BeforeCreateTable event of the database fires before the Table Designer appears, and the AfterCreateTable event fires after the Table Designer is closed, even if you didn’t save the table. For ideas on working with the Table Designer, see “DBF, CDX, FPT, CDX—Hike!” and “What Power Tools?” in Section 2.

Example

CREATE MyNewTable

Usage

MODIFY STRUCTURE

MODIFY STRUCTURE, or, as most FoxPro people write it, MODI STRU, also brings up the Table Designer. In this case, though, it shows the structure for the table open in the current work area. If no table is open there, the Open dialog appears to let you choose one. If the table belongs to a database and Database Events are turned on, the BeforeModifyTable event of the database fires before the Table Designer appears, and the AfterModifyTable event fires after the Table Designer is closed.

Back in the dark ages, we toyed with the idea of changing a table’s structure in a program by playing a macro against the old version of the Table Designer. But with Visual FoxPro’s inclusion of ALTER TABLE, there’s no reason to even think about this anymore.

The Table page of the Table Designer shows a total length for the record. Unfortunately, for records that accept nulls in any field, it's wrong. It's one less than the correct value returned by RECSIZE().

See Also

AFields(), Alter Table, AfterCreateTable, AfterModifyTable, BeforeCreateTable, BeforeModifyTable, Create Cursor, Create Database, Create From, Create Table, Display and List, RecSize()