Freigeben über


Table Creation

Tables store your data in a row and column format, similar to a spreadsheet. Each row represents a record, and each column represents the fields in the records. You can create a table in a database, or just create a free table not associated with a database. If you put the table in a database, you can create long table and field names for database tables. You can also take advantage of data dictionary capabilities for database tables, default field values, and field- and record-level rules, as well as triggers.

Designing Database vs. Free Tables

A Visual FoxPro table, or .dbf file, can exist in one of two states: either as a database table (a table associated with a database) or as a free table that is not associated with any database. Tables associated with a database have several benefits over free tables. When a table is a part of a database you can create:

  • Long names for the table and for each field in the table.
  • Captions and comments for each table field.
  • Default values, input masks, and format for table fields.
  • Default control class for table fields.
  • Field-level and record-level rules.
  • Primary key indexes and table relationships to support referential integrity rules.
  • One trigger for each INSERT, UPDATE, or DELETE event.

Some features apply only to database tables. For information about associating tables with a database, see Developing Databases.

Database tables have properties that free tables do not have.

You can design and create a table interactively with the Table Designer, accessible through the Project Manager or the File menu, or you can create a table programmatically with the language.

Interactive Table Creation

When you need to build a new table, you can get assistance from the Table Wizard, or use the Table Designer and interactively set up a table with the fields you need.

Remember these main points when you set up a table:

  • Make the data type for a field match the kind of information you are going to store in it.
  • Make the field wide enough to accommodate the information it will display.
  • Set an appropriate number of decimal places for Numeric or Float fields.
  • Check NULL if you want the field to accept .NULL. as a value.

Programmatic Table Creation

You use the following commands to create and edit a table programmatically:

Commands for Creating and Editing Tables

ALTER TABLE CLOSE TABLES
CREATE TABLE DELETE FILE
REMOVE TABLE RENAME TABLE
DROP TABLE  

See Also

Working with Tables | Creating a Database Table | Creating a Free Table | Naming a Table | Renaming a Table | Viewing Data in Tables | Choosing Data Types | Moving Around in a Table | Customizing a Browse Window | Customizing Tables