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
Element | Description | Restrictions | Syntax |
---|---|---|---|
database | Name of a database to which to connect | The database must exist | Database Name |
Usage
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.
SELECT DBINFO('dbhostname')
FROM systables
WHERE tabid = 1;
(constant) |
---|
rd_lab1 |