Creates a database environment and a connection, and specifies a
connection name for that association.
A connection specifies an association between the set of cursors,
intermediate result tables, and procedures in all modules of an
application and the database environment currently attached.
A database environment is one or more databases that can be
attached or detached as a unit. The connection name designates a
particular connection and database environment. When you execute
a procedure, it executes in the context of a connection.
When you issue a CONNECT statement, SQL creates a new connection
from all the procedures in your application and creates a
new environment from all the databases named in the CONNECT
statement. The new environment can include databases already
attached in the default environment.
There are two ways to attach a database to the default
environment:
o Use an ATTACH statement to specify a database environment at
run time. All the databases you specify with subsequent ATTACH
statements become part of the default environment.
o Use a DECLARE ALIAS statement to specify a database
environment at compile time in precompiled SQL and SQL module
language. All the databases that you specify using DECLARE
ALIAS statements also become part of the default environment.
A CONNECT statement creates a new connection with a new set
of attachments, and does an implicit SET CONNECT to that new
connection. Although a CONNECT statement does not create a
transaction, each connection has its own implicit transaction
context. You can issue two different CONNECT statements that
attach to the same database, but each attach is unique.
Once you have specified a connection name in a CONNECT statement,
you can refer to that connection name in subsequent SET CONNECT
statements. You can use a SET CONNECT statement to specify a new
connection for an application to run against without having to
detach and recompile queries. See the SET_CONNECT statement for
more information.
The DISCONNECT statement detaches from databases, ends the
transactions in the connections that you specify, and rolls back
all the changes you made since those transactions began.
Additional Information:
explode
extract