Declaring a Database

From InterBase

Go Up to Working with Databases


Before a database can be opened and used in a program, it must first be declared with SET DATABASE to:

  • Establish a database handle.
  • Associate the database handle with a database file stored on a local or remote node.

A database handle is a unique, abbreviated alias for an actual database name. Database handles are used in subsequent CONNECT, COMMIT RELEASE, and ROLLBACK RELEASE statements to specify which databases they should affect. Except in dynamic SQL (DSQL) applications, database handles can also be used inside transaction blocks to qualify, or differentiate, table names when two or more open databases contain identically named tables.

Each database handle must be unique among all variables used in a program. Database handles cannot duplicate host-language reserved words, and cannot be InterBase reserved words.

The following statement illustrates a simple database declaration:

EXEC SQL
SET DATABASE DB1 = 'employee.ib';

This database declaration identifies the database file, employee.ib, as a database the program uses, and assigns the database a handle, or alias, DB1.

If a program runs in a directory different from the directory that contains the database file, then the file name specification in SET DATABASE must include a full path name, too. For example, the following SET DATABASE declaration specifies the full path to employee.ib:

EXEC SQL
SET DATABASE DB1 = '/InterBase/examples/employee.ib';

If a program and a database file it uses reside on different hosts, then the file name specification must also include a host name. The following declaration illustrates how a Unix host name is included as part of the database file specification on a TCP/IP network:

EXEC SQL
SET DATABASE DB1 = 'jupiter:/usr/interbase/examples/employee.ib';

On a Windows network that uses the NetBEUI protocol, specify the path as follows:

EXEC SQL
SET DATABASE DB1 = '//venus/C:/InterBase/examples/employee.ib';

Topics

Advance To: