DATABASE statement

Use the DATABASE statement to open an accessible database as the current database. This statement is an extension to the ANSI/ISO standard for SQL.

Syntax

DATABASEdatabase [ EXCLUSIVE ]
Element Description Restrictions Syntax
database Name of a database to which to connect The database must exist Database Name

Usage

You can use the DATABASE statement to select any database of your database server instance. To select a database on another database server, include the name of the database server with the database name:
DATABASE stores_demo@db_titinius;
You can also specify the database as a host variable that contains a valid database environment:
DATABASE db_varX;
Here the contents of db_varX must correspond to one of the formats in the Database Name syntax diagram.

If besides the name of the database you also provide the name of the current (or of another) database server instance, the database server name cannot include uppercase characters.

If the DATABASE statement specifies only a database name that corresponds to no database of the current server instance, the database server examines the DBPATH environment variable setting, and opens the specified database if a server is found. If no database is found, or if its server is offline, the DATABASE statement fails with an error. For more information, see the CONNECT statement topic Only Database Specified.

Issuing the DATABASE statement when a database is already open closes the current database before opening the new one. Closing the current database releases any cursor resources that the database server holds, invalidating any cursors that you have declared up to that point. If the user specification was changed through a SET SESSION AUTHORIZATION statement, the original user name is restored when the new database is opened.

If a previous CONNECT statement has established an explicit connection to a database, and that connection is still your current connection, you cannot use the DATABASE statement (nor any SQL statement that creates an implicit connection) until after you use DISCONNECT to close the explicit connection.

The current user (or PUBLIC) must have the Connect privilege on the database that is specified in the DATABASE statement. The current user cannot have the same user name as an existing role in the database.

DATABASE is not a valid statement in multistatement PREPARE operations.

You can use the 'dbhostname' option to retrieve the host name of the database server to which a database client is connected. This option retrieves the physical computer name of the computer on which the database server is running. In the following example, the user enters the 'dbhostname' option of DBINFO in a SELECT statement to retrieve the host name of the database server instance to which DB-Access is connected:
SELECT DBINFO('dbhostname') 
   FROM systables
   WHERE tabid = 1;
The following table shows the result of this query.
(constant)
rd_lab1