Name

DISCONNECT Statement

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

Platform

Command

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

or 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.

MySQL

Not supported.

Oracle

Oracle allows DISCONNECT only in its ad hoc query tool, SQL*Plus, using this syntax:

DISC[ONNECT]

In this usage, the command ends the current session with the database server but otherwise allows work in SQL*Plus to continue. For example, a programmer can continue to edit the buffer, save run files, and so on, but must establish a new connection to issue any SQL commands. Exiting SQL*Plus and returning to the filesystem ...

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.