Name

DISCONNECT Statement

Synopsis

The DISCONNECT statement terminates one or more connections created between the current SQL process and the database server.

Platform

Command

DB2

Supported, with limitations

MySQL

Not supported

Oracle

Supported, with limitations

PostgreSQL

Not supported

SQL Server

Supported, with limitations

SQL2003 Syntax

DISCONNECT {CURRENT | ALL | connection_name | DEFAULT}

Keywords

CURRENT

Closes the currently active user connection.

ALL

Closes all open connections for the current user.

Rules at a Glance

DISCONNECT is used to disconnect a named SQL session (connection_name), the CURRENT connection, the DEFAULT connection, or ALL connections held by the user. For example, we can disconnect a single session called new_york:

DISCONNECT new_york

In the next example, we might want to disconnect all currently open sessions for the current user process:

DISCONNECT ALL

Programming Tips and Gotchas

DISCONNECT is not universally supported across platforms. Do not build cross-platform applications based on DISCONNECT unless you’ve made provisions to disconnect SQL sessions using each platform’s preferred disconnection methodology.

DB2

DB2 supports the ANSI standard for DISCONNECT in embedded SQL only. DISCONNECT can drop one or more connections only after a commit or rollback operation succeeds for the sessions to be dropped. You can also use the RELEASE statement to place a connection in a disconnect-pending condition.

MySQL

Not supported.

Oracle

Oracle allows DISCONNECT ...

Get SQL in a Nutshell, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.