Partager via


SET DATABASE Command

Specifies the current database. SET DATABASE is scoped to the current data session. When one or more databases are open, you can also specify the current database by selecting an open database from the Database drop-down list on the Standard toolbar.

You can have many databases open at the same time, but only one can be the current database. Commands and functions that manipulate open databases, such as ADD TABLE and DBC( ), operate on the current database.

SET DATABASE TO [DatabaseName]

Parameters

  • DatabaseName
    Specifies the name of an open database to make the current database. If you omit DatabaseName, no open database is made the current database. You can specify an empty string for DatabaseName, which is treated as if you omitted DatabaseName.

Remarks

Visual FoxPro might automatically open databases when executing a query or a form.

Example

The following example creates two databases named mydbc1 and mydbc2, and a table named table1. SET DATABASE is used to make mydbc1 the current database, and table1 is added to mydbc1 when it is created. The table is then closed and removed from mydbc1. SET DATABASE is used to make mydbc1 the current database, and ADD TABLE is then used to add the table to mydbc2. RENAME TABLE is used to change the name of the table from table1 to table2.

CREATE DATABASE mydbc1
CREATE DATABASE mydbc2
SET DATABASE TO mydbc1
CREATE TABLE table1 (cField1 C(10), n N(10))  && Adds table to mydbc1
CLOSE TABLES     && A table must be closed to remove it from a database
REMOVE TABLE table1
SET DATABASE TO mydbc2
ADD TABLE table1
RENAME TABLE table1 TO table2

See Also

ADD TABLE | CLOSE DATABASES | DBC( ) | DBGETPROP( ) | DBSETPROP( ) | DELETE DATABASE | DISPLAY TABLES | MODIFY DATABASE | OPEN DATABASE | REMOVE TABLE | SET DATASESSION