How to Add Fields to a Table in Visual FoxPro Programmatically

Last reviewed: November 12, 1995
Article ID: Q139158
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

In previous versions of FoxPro, the only way to alter the structure of a table programmatically was to create a new table that contained the new structure and then append the data from the old table.

Visual FoxPro now includes the ALTER TABLE command, which allows you to alter the structure of an existing table programmatically. This article shows by example how to add a field to an existing table.

MORE INFORMATION

This example uses the Customer.dbf table that is part of the Testdata.dbc database. These files are located in the \Vfp\Samples\Data directory. The following code adds a new field named Newfield to the Customer.dbf table. The new field is a character field with a width of 20.

   OPEN DATA testdata
   USE customer
   ALTER TABLE customer ADD COLUMN Newfield C(20)

After running this code, use the MODIFY STRUCTURE or BROWSE command to see the changes to the table structure.

For more information on the ALTER TABLE command, please see the ALTER TABLE command topic in the Visual FoxPro Help file.


Additional reference words: 3.00 VFoxWin
KBCategory: kbprg kbhowto kbcode
KBSubcategory: FxprgTable


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 12, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.