VFP: Learn How to Create Table in Visual FoxPro

VFP: Learn How to Create Table in Visual FoxPro

  • Blog
  • 2 mins read

In this tutorial, you will learn how to create a table in Visual FoxPro.

In Visual FoxPro, you can create a table inside a database or outside of a database. Here I am giving both the examples. First, check the syntax for creating a table:

CREATE TABLE | DBF TableName1 [NAME LongTableName] [FREE] 
    [CODEPAGE = nCodePage]
    ( FieldName1 FieldType [( nFieldWidth [, nPrecision] )] [NULL | NOT NULL] 
    [CHECK lExpression1 [ERROR cMessageText1]] 
    [AUTOINC [NEXTVALUE NextValue [STEP StepValue]]] [DEFAULT eExpression1] 
    [PRIMARY KEY | UNIQUE [COLLATE cCollateSequence]] 
    [REFERENCES TableName2 [TAG TagName1]] [NOCPTRANS]
    [, FieldName2 ... ] 
    [, PRIMARY KEY eExpression2 TAG TagName2 |, UNIQUE eExpression3 TAG TagName3 
    [COLLATE cCollateSequence]]
    [, FOREIGN KEY eExpression4 TAG TagName4 [NODUP] 
    [COLLATE cCollateSequence] 
    REFERENCES TableName3 [TAG TagName5]] [, CHECK lExpression2 [ERROR cMessageText2]] ) 
    | FROM ARRAY ArrayName

Create Table Outside of a Database

The following sequence of commands will set the default directory to D:\MYVFPPROJECT, then will close all databases, and then will create a table salesman:

SET DEFAULT TO D:\MYVFPPROJECT
CLOSE DATABASES
CREATE TABLE Salesman ;
   (SalesID c(6), ;
   SaleName Character(20))

You can create a table by using Visual FoxPro visual editor. Follow these steps:

SET DEFAULT TO D:\MYVFPPROJECT
CLOSE DATABASES
CREATE Salesman

After giving the command, the create table window will open, where you can specify the fields as shown in the below image:

Create Table Visual FoxPro

Create Table Inside a Database

SET DEFAULT TO D:\MYVFPPROJECT
CLOSE DATABASES
OPEN DATABASE SALES
CREATE TABLE Salesman ;
(SalesID c(6) PRIMARY KEY, ;
SaleName Character(20))

Also, you can give the Create Salesman command in the command window to create a table in Visual FoxPro using table designer.

See also: