How to Create or Modify a Database in an Application

Last reviewed: April 29, 1996
Article ID: Q93633
The information in the article applies to:
  • Micorsoft Visual FoxPro for Windows, version 3.0
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6x
  • Microsoft FoxPro for MS-DOS, versions 1.x, 2.0, 2.5x, 2.6x
  • Microsoft FoxBASE+ for MS-DOS, version 2.1

SUMMARY

In FoxPro 2.x, to create or modify a database under program control, you can use the COPY TO <name> STRUCTURE EXTENDED, the CREATE <name1> FROM <name2> command.

In Visual FoxPro, you can use the ALTER TABLE command.

Also, you can use the CREATE TABLE command in any version of FoxPro.

MORE INFORMATION

The following code examples create a new database named TEMP that contains one field. The field is named LASTNAME and is 30 characters long.

FoxPro 2.x

   USE anyfile
   COPY TO temp STRUCTURE EXTENDED
   USE temp

   APPEND BLANK
   REPLACE field_name WITH 'lastname'
   REPLACE field_len WITH 30
   REPLACE field_type WITH 'C'
   REPLACE field_dec WITH 0
   CREATE newfile FROM temp

NOTE: To add more than one field to the table, perform another APPEND BLANK and then the REPLACE sequence again.

The COPY STRUCTURE EXTENDED command creates a new database file that describes the structure of the original database. Each record of the new database describes a field of the original database.

NOTE: The COPY STRUCTURE EXTENDED and CREATE FROM commands also work in stand-alone applications created with the FoxPro Distribution Kit.

Visual FoxPro

   USE anyfile
   ALTER TABLE Temp  ADD COLUMN  "Lastname" C(10)

CREATE TABLE Command

You can also use the CREATE TABLE command to modify or create a database. Its syntax is as follows:

   CREATE table <dbf_name>(<fname1> <type> [(<precision>[,
<scale>])[,
      <fname2> ...]])

The following example creates a table with the NAME, ADDR, CITY, ZIP, and SALARY fields, plus a memo field called COMMENTS:

   CREATE Table employee ;
      (name C(20), addr C(30), city C(30), zip C(5), salary N(8,2), ;
         comments M)


Additional reference words: VFoxWin 3.00 FoxDos FoxWin 1.00 1.x 2.00 2.10
2.50 2.50a 2.50b 2.60 2.60a dbf
KBCategory: kbprg kbcode
KBSubcategory: FxtoolGeneral


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: April 29, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.