Condividi tramite


Creating a Database

When you create a database, you gather tables together into one collection and gain the benefit of data dictionary features.

A data dictionary gives you greater flexibility in designing and modifying the database, and frees you from having to write code to create field-level and row-level validation or to ensure the uniqueness of values within primary key fields. The Visual FoxPro data dictionary enables you to create or specify:

  • Primary and candidate keys.
  • Persistent relationships between database tables.
  • Long names for tables and fields.
  • Captions on fields that display in Browse windows and Grid columns as headers.
  • Default values on fields.
  • The default control class used in forms.
  • Input masks and display formats for fields.
  • Field-level rules and record-level rules.
  • Triggers.
  • Stored procedures.
  • Connections to remote data sources.
  • Local and remote views.
  • Comments for each field, table, and database.

Some data dictionary features, such as long field names, primary and candidate keys, default values, field-level and record-level rules, and triggers, are stored in the .dbc file but are created as part of the process of building a table or view. For information about these features, see Working with Tables, and Creating Views.

Collecting Tables into a Database

To collect tables into a database, you need to create a database container to hold all of the objects such as views, connections, and stored procedures associated with the tables that make up your database.

To create a new database

For example, the following code creates and exclusively opens a new database called Sample:

CREATE DATABASE Sample

When you create a new database, it is empty, containing no associated tables or other objects. Adding a table creates links between the table file and the database container. The link information stored in the database about a table is a forward link. The link information stored in the table about the database container is the backlink.

Links specify the associations between a database container and tables.

Using the Database Wizard

You can use the Database Wizard to help you create a new database. The wizard provides templates and poses a series of questions to help you set up your database based on your answers.

To create a database using the Database Wizard

  1. In the Project Manager, select the Data tab and select Databases.
  2. Choose New.
  3. Choose the Database Wizard button.
  4. Follow the instructions on the wizard screens.

You can also access the Database Wizard from the menu by choosing New from the File menu, selecting Database, and selecting the Database Wizard option.

The wizard provides templates for tables and views, indexes, primary keys, and relationships you can choose or edit.

You can use the following commands and functions to work with a database and its objects programmatically.

Commands and functions that manipulate databases and database objects

ADATABASES( ) CREATE VIEW MODIFY CONNECTION
ADBOBJECTS( ) DBC( ) MODIFY DATABASE
ADD TABLE DBGETPROP( ) MODIFY PROCEDURE
ALTER TABLE DBSETPROP( ) MODIFY STRUCTURE
APPEND PROCEDURES DELETE CONNECTION MODIFY VIEW
CLOSE DATABASE DELETE DATABASE OPEN DATABASE
COPY PROCEDURES DELETE VIEW PACK DATABASE
CREATE CONNECTION DISPLAY DATABASE RENAME TABLE
CREATE DATABASE DROP TABLE REMOVE TABLE
CREATE SQL VIEW INDBC( ) SET DATABASE
CREATE TABLE LIST DATABASE VALIDATE DATABASE

See Also

Creating Databases | Adding Tables to a Database | Browse | Removing a Table from a Database | Updating Table and Database Links | Project Manager | CREATE DATABASE | Database Wizard | Database Designer | Designing Databases