The CONNECT statement establishes a logical session between the client application and a specific database or database server. After a successful CONNECT, subsequent SQL statements are executed in the context of that session until it is explicitly terminated with DISCONNECT or the application ends. The statement is most common in IBM DB2, Informix, and other ANSI/ISO-compliant CLI environments, where it is part of the language rather than merely a client-side command. CONNECT does not modify data; it only authenticates the user, allocates resources, and sets the current database, schema, and default settings such as isolation level. Some systems allow multiple concurrent connections; others permit only one active CONNECT at a time. Because credentials travel over the network, use encrypted channels (TLS/SSL) or parameterized connection objects to avoid leaking sensitive information. CONNECT is not available in MySQL or PostgreSQL SQL grammar but has equivalent client commands (e.g., \connect in psql).
user_name
- STRING Login or authorization ID to authenticate (optional if using OS credentials)password
- STRING Plain-text or parameterized password associated with user_nameIBM DB2 Version 1 (1983) and later formalized in the ANSI SQL/CLI (SQL-92) standard
CONNECT opens a new session to a database, while DISCONNECT cleanly terminates it, releasing server and client resources.
No. Those systems expose connection switching as client commands (\connect and \r in psql, \connect in the mysql client) but do not include CONNECT in their SQL grammar.
Pass credentials through environment variables, encrypted wallets, or parameter markers (host variables) rather than hard-coding them inside scripts.
Most databases prohibit CONNECT within stored procedures for security and transactional integrity reasons. Always check your vendor documentation.