sys.dm_exec_sessions#
Returns one row per authenticated session.
sys.dm_exec_sessions is a server-scope view that shows information about all active user connections. This information includes client version, client program name, client login time, login user, current session setting, and more. Use sys.dm_exec_sessions to first view the current system load and to identify a session of interest, and then learn more information about that session by using other dynamic management views or dynamic management functions.
Column name |
Data type |
Nullable |
Description |
|---|---|---|---|
|
smallint |
No |
Identifies the session associated with each active primary connection. |
|
datetime |
No |
Time when session was established. Sessions that haven’t
completely logged in at the time this DMV is queried, are shown
with a login time of |
|
nvarchar(128) |
Yes |
Name of the client workstation that’s specific to a session.
The value is Security note: The client application provides the
workstation name and can provide inaccurate data. Don’t rely on
|
|
nvarchar(128) |
Yes |
Name of client program that initiated the session. The value is
|
|
int |
Yes |
Process ID of the client program that initiated the session.
The value is |
|
int |
Yes |
TDS protocol version of the interface used by the client to
connect to the server. The value is |
|
nvarchar(32) |
Yes |
Name of library/driver being used by the client to communicate
with the server. The value is |
|
varbinary(85) |
No |
Windows security ID associated with the login. |
|
nvarchar(128) |
No |
SQL Server login name under which the session is currently
executing. For the original login name that created the
session, see |
|
nvarchar(128) |
Yes |
Windows domain for the client if the session is using Windows
Authentication or a trusted connection. This value is |
|
nvarchar(128) |
Yes |
Windows user name for the client if the session is using
Windows Authentication or a trusted connection. This value is
|
|
nvarchar(30) |
No |
Status of the session. Possible values:
|
|
varbinary(128) |
Yes |
|
|
int |
No |
CPU time, in milliseconds, used by this session. |
|
int |
No |
Number of 8-KB pages of memory used by this session. |
|
int |
No |
Total time, in milliseconds, for which the session (requests within) were scheduled for execution. |
|
int |
No |
Time, in milliseconds, since the session was established. |
|
int |
No |
ID of the endpoint associated with the session. |
|
datetime |
No |
Time at which the last request on the session began. This time includes the currently executing request. |
|
datetime |
Yes |
Time of the last completion of a request on the session. |
|
bigint |
No |
Number of physical reads performed, by requests in this session, during this session. |
|
bigint |
No |
Number of physical writes performed, by requests in this session, during this session. |
|
bigint |
No |
Number of logical reads performed, by requests in this session, during this session. |
|
bit |
No |
|
|
int |
No |
|
|
nvarchar(128) |
Yes |
|
|
nvarchar(3) |
Yes |
|
|
smallint |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
bit |
No |
|
|
smallint |
No |
Transaction isolation level of the session.
|
|
int |
No |
|
|
int |
No |
|
|
bigint |
No |
Number of rows returned on the session up to this point. |
|
int |
No |
ID of the last error returned on the session. |
|
varbinary(85) |
No |
Windows security ID that is associated with the
|
|
nvarchar(128) |
No |
SQL Server login name that the client used to create this session. Can be a SQL Server authenticated login name, a Windows authenticated domain user name, or a contained database user. The session might have been through many implicit or explicit context switches after the initial connection. |
|
datetime |
Yes |
Time of the last successful logon for the |
|
datetime |
Yes |
Time of the last unsuccessful logon attempt for the
|
|
bigint |
Yes |
Number of unsuccessful logon attempts for the
|
|
int |
No |
ID of the workload group to which this session belongs. |
|
smallint |
No |
ID of the current database for each session. |
|
int |
Yes |
ID of the database authenticating the principal. For logins,
the value is |
|
int |
No |
Number of open transactions per session. |
|
int |
No |
The identifier for the node that this distribution is on. |
|
bigint |
No |
Number of page server reads performed, by requests in this session, during this session. |
|
uniqueidentifier |
Yes |
ID of the contained availability group. |
Permissions#
Everyone can see their own session information.
Requires VIEW SERVER STATE to see all sessions on the server.
Relationship cardinalities#
From |
To |
On/Apply |
Relationship |
|---|---|---|---|
sys.dm_exec_sessions |
[sys.dm_exec_requests](sys-dm-exec-requests) |
session_id |
One-to-zero or one-to-many |
sys.dm_exec_sessions |
[sys.dm_exec_connections](sys-dm-exec-connections) |
session_id |
One-to-zero or one-to-many |
Examples#
A. Find users that are connected to the server#
The following example finds the users that are connected to the server and returns the number of sessions for each user.
SELECT login_name,
COUNT(session_id) AS session_count
FROM sys.dm_exec_sessions
GROUP BY login_name;
B. Find information about a query’s own connection#
The following example gathers information about a query’s own connection:
SELECT c.session_id,
c.net_transport,
c.encrypt_option,
c.auth_scheme,
s.host_name,
s.program_name,
s.client_interface_name,
s.login_name,
s.nt_domain,
s.nt_user_name,
s.original_login_name,
c.connect_time,
s.login_time
FROM sys.dm_exec_connections AS c
INNER sys.dm_exec_sessions AS s
ON c.session_id = s.session_id
WHERE c.session_id = @@SPID;