Name

SET CONNECTION Statement

The SET CONNECTION statement allows users to switch between several open connections on one or more database servers.

Platform

Command

MySQL

Not supported

Oracle

Not supported

PostgreSQL

Not supported

SQL Server

Supported, with limitations

SQL2003 Syntax

SET CONNECTION {DEFAULT | connection_name}

Keywords

connection_name

Names the connection of the current session. If the connection_name is different from the current session connection name, the connection context is switched to the connection_name.

DEFAULT

Switches to the default connection from any other connection. This enables rapid switching to the default connection without knowing its name.

Description

This command does not end a connection. Instead, it switches from the current connection to the connection named (making it the current connection), or from the current connection to the default connection. When switching between connections, the old connection becomes dormant (without committing any changes), while the new connection becomes active.

Rules at a Glance

SET CONNECTION does not create a connection; it merely switches your connection context. Use the CONNECT command to create a new connection, and use DISCONNECT to terminate a connection.

Programming Tips and Gotchas

The SET CONNECTION command is not frequently used, since many users connect programmatically via ODBC, JDBC, or some other connectivity method. However, on those platforms that support SET CONNECTION, the command can be very useful for rapidly ...

Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.