Using SET DATABASE
Go Up to Declaring and Initializing Databases
The SET DATABASE
statement is used to:
- Declare a database handle for each database used in a SQL program.
- Associate a database handle with an actual database name. Typically, a database handle is a mnemonic abbreviation of the actual database name.
SET DATABASE
instantiates a host variable for the database handle without requiring an explicit host variable declaration. The database handle contains a pointer used to reference the database in subsequent SQL statements. To include a SET DATABASE
statement in a program, use the following syntax:
EXEC SQL SET DATABASE handle = 'dbname';
A separate statement should be used for each database. For example, the following statements declare a handle, DB1, for the employee.ib
database, and another handle, DB2, for employee2.ib
:
EXEC SQL SET DATABASE DB1 = 'employee.ib'; EXEC SQL SET DATABASE DB2 = 'employee2.ib';
Once a database handle is created and associated with a database, the handle can be used in subsequent SQL database and transaction statements that require it, such as CONNECT
.
- Note:
SET DATABASE
also supports user name and password options. For a complete discussion ofSET DATABASE
options, see Working with Databases.