Tutorial: FoxPro A - Database Creation & Display

Dr. Thomas E. Hicks
Computer Science Department
Trinity University


  1. General Definitions
  2. Quit - Exit Database
  3. Set Default To - Assign Default Drive/Directory
  4. Create - Create A New Database
  5. ESC key - Abort Process Key
  6. List - List Fields
  7. List To Print - Print the Field Listing
  8. Append - Add New Record(s) To End Of Database
  9. Display Structure - Display Database Layout
  10. List Structure - Display Database Layout Without Pause
  11. List Structure To Print - Print Database Layout Without Pause
  12. Display Structure To Print - Print Database Layout With Pause
  13. Use - Open Database
  14. Clear - Clear Console
  15. Possible Exam/Quiz Questions - FoxPro A

General Definitions 

database management system (DBMS): <--> a collection of interrelated data and programs to access that data.

database table: <--> a collection of information pertaining to some type of entity. A database table might represent an entity such as clients (contact manager) , an entity such as parts (inventory management system), an entity such as students (grade book program), etc. Let us consider a Client Database.

record: <--> the information related to one entity (one part, one client, or one student).In a Client database, each record would contain the information related to one client.

fields: <--> the individual sub-components of one record. The fields within a client database might be Name, Address, City, State, Zip, Phone, Male, Notes. 



All of the following FoxPro Commands Can Be Entered Into The Command Window (See Below)
(these commands are not case sensitive)


quit - Exit Database

Quit <-- quit will exit the FoxPro software. All database files and indexes are automatically saved. 


set default to - Assign Default Drive/Directory

Set Default To Drive:Path <-- sets the default directory to the specified directory. A database application is generally formed by many files. In order to avoid problems while learning FoxPro, it is essential to place all of the files in an application in the same directory. Setting the default directory should be one of the first things you do. Create the directory using Windows.

Set Default To A:\Client <-- set the default directory to be Client [ at the root of the floppy disk in the A drive].

Set Default To C:\346\Demo <-- set the default directory to be Demo [inside the 346 directory which is at the root of the C hard drive. 


create - Create A New Database

create FileName <-- create a new database file. The create command dumps you into the file creation program where you are given the opportunity to determine the database structure/layout. You will select field names, field types (Character, Logical, Date, Currency, Numeric, and Memo, etc.), and field size.

Create Client <-- create a database, called Client.DBF, in the default directory.

Create C:\305\Client <-- create a database, called Client.DBF, in the 305 directory on the C hard drive. You can establish the directory path, but it is much better to set the default directory and allow all files to be automatically grouped together in this default directory

When a new database is constructed, each field must have a symbolic name by which it can be referenced. These field names are 1-10 characters in length. The field name may be constructed from any characters in the set {A,B,C,...,Z,Underscore(_)}. Field names are not case sensitive.

Associated with each field will be a datatype. The datatypes that we will explore will be character, numeric, logical, date, and memo. Select a datatype that best fits the type of information that you plan to process. The character and numeric datatypes require that you specify the number of characters that are to be stored. The Client.DBF has been created below.

The default directory has been set to folderC:|Client. The tab key is used  to advance to the next block when deciding upon the fields. The 9 fields of the Client database table (Client.DBF) have now been chosen for the database structure. Select the titles for these fields wisely.

When finished designing the layout, use the mouse and select/press OK. When asked "Input Data Records Now", select/push the YES button. (See Below)

This will dump you into a crude data entry editor. Just for practice, try entering a few records.

Valid information for  logical fields can be Y or y (Yes), N or n (No), T or t (True), F or (False).
Valid information for  Numeric  fields can be +,-,0,1,2,3,4,5,6,7,8,9.
Valid information for  character  fields can be any keyboard characters.
Valid information for the date field can be legal values in the form XX/XX/XX (the editor will provide the /'s).

The Notes field is a memo field; the memo note has memo in lower case; this tells us that there has been no memo information recorded for this file. In order to record memo information with this crude data entry editor, double click on the word memo with your mouse. This will bring up an editing box.

Using the mouse, press/select the   button to close the editing box; all changes will be saved. Press the ESC key to discard the memo changes. Note that Memo becomes capitalized once Notes contains some information. (See Below)

The database record information is updated when you fill a field, when you hit the tab key, and when you hit the enter key.  You may add as many records as you like. When finished adding records and wish to cancel/abort the editor, hit the ESC key.

Examination of the A:\Client folder reveals 2 files. The database table information is contained in Client.DBF. The memo information is stored in the corresponding FPT file, called Client.FPT


ESC key - Abort Process Key

<ESC> <-- try to abort/terminate that which you are doing. 


list - List Fields 

List [fields] <-- an uninterrupted display of database information. The list command will always move the read/write pointer to first logical record and display all of the fields of all records. Upon completion, the read/write pointer will always reside at the end of the file. Since the display is uninterrupted, there will be no pause when the screen is full.

List <-- uninterrupted display of specified fields of all records.

The List command was executed in the graphic above.

The name of the database open in the active work area (Client) is specified in the left corner of the FoxPro status bar. The path to that database (C:\Client\Client.DBF) is specified on the left side of the FoxPro status bar. The status bar specifies that there are 3 records in the database. We will discuss the read/write pointer in FoxProB; the status bar specifies that the read/write pointer is at EOF (End Of File). The status states that this database is not shared, it is opened exclusively for one user.

List Name, State, Phone <-- uninterrupted display of the Name field, the State field, and the Phone of all records.

List Phone, Name, State <-- uninterrupted display of the Phone field, the Name field, and the State field of all records. 


list to print - Print the Field Listing

List Name, Phone To Print <-- uninterrupted display and printing of the Name field and the Phone of all records.

List Phone, Name, State To Print <-- uninterrupted display of the Phone field, the Name field, and the State field of all records. 


append - Add New Record(s) To End Of Database

Append <-- move the read/write pointer to the end of the file and evoke a very crude editor for data entry. Append is used to add additional records to the database.


display structure - Display Database Layout With Pause

Display Structure <-- display the database layout, the number of records, and the creation date. It will pause when the screen is full.

Structure for table : C:\Client\client.DBF
Number of records : 100
Date of last update: 01/01/98
Memo file block size: 64
Code Page: 1252

Field   Field Name  Type        Width   Dec
1       NAME        Character      26
2       ADDRESS     Character      30
3       CITY        Character      16
4       STATE       Character       2
5       ZIP         Character       8
6       PHONE       Character      12
7       MALE        Logical         1
8       NO          Numeric         4     0
9       NOTES       Memo            4
** Total **                       104 


list structure - Display Database Layout Without Pause

List Structure <-- display the database layout, the number of records, and the creation date. It will not pause when the screen is full.

Structure for table : C:\Client\client.DBF
Number of records : 100
Date of last update: 01/01/98
Memo file block size: 64
Code Page: 1252

Field   Field Name  Type        Width   Dec
1       NAME        Character      26
2       ADDRESS     Character      30
3       CITY        Character      16
4       STATE       Character       2
5       ZIP         Character       8
6       PHONE       Character      12
7       MALE        Logical         1
8       NO          Numeric         4     0
9       NOTES       Memo            4
** Total **                       104 


list structure to print - Print Database Layout Without Pause

List Structure To Print <-- display and print the database layout, the number of records, and the creation date. It will not pause when the screen is full. 


display structure to print - Print Database Layout With Pause

Display Structure  To Print <-- display and print the database layout, the number of records, and the creation date. It will pause when the screen is full.

The difference between List Structure To Print and Display Structure To Print is only the pause when the screen is full. 


use - Open Database 

use FileName <-- close any database open in the current work area and opens the specified database. The database must have a .DBF extension. The read/write record pointer is positioned at the first record when file is opened/re-opened.

Use Client       <-- close and database open in the current work area and then open database file Client.DBF in the current work area.
Use Students  <-- close and database open in the current work area and then open database file Students.DBF in the current work area.
Use          <-- close any database open in the current work area.


clear - Clear Console 

Clear <--- clear the current user-defined window (desktop if none). 


Possible Exam/Quiz Questions - FoxPro #A

May be accessed through URL: http://www.cs.trinity.edu/~thicks
May also be accessed through URL: http://carme.cs.trinity.edu
This Document May Not Be Printed or Reproduced Without Written Permission.
 2003 Copyright : Dr. Thomas E. Hicks
Permission granted : Professional Educators & College Students may print one copy of this page!

Dr. Thomas E. Hicks

Computer Science Department    
Trinity University

"Dr. Web"