Attaching to Multiple Databases

From InterBase

Go Up to Opening a Database


CONNECT can attach to multiple databases. To open all databases specified in previous SET DATABASE statements, use either of the following CONNECT syntax options:

EXEC SQL
CONNECT ALL;
EXEC SQL
CONNECT DEFAULT;

CONNECT can also attach to a specified list of databases. Separate each database request from others with commas. For example, the following statement opens two databases specified by their handles:

EXEC SQL
CONNECT DB1, DB2;

The next statement opens two hard-coded database files and also assigns them to previously declared handles:

EXEC SQL
CONNECT 'employee.ib' AS DB1, 'employee2.ib' AS DB2;
Tip:
Opening multiple databases with a single CONNECT is most effective when a program’s database access is simple and clear. In complex programs that open and close several databases, that substitute database names with host-language variables, or that assign multiple handles to the same database, use separate CONNECT statements to make program code easier to read, debug, and modify.

Advance To: