sp_who (T-SQL)

Provides information about current Microsoft® SQL Server™ users and processes. The information returned can be filtered to return only those processes that are not idle.

Syntax

sp_who [[@login_name =] 'login']

Arguments
[@login_name =] 'login'
Is a user login name on SQL Server. login is sysname, with a default of NULL. If no name is specified, the procedure reports all active users of SQL Server. login can also be a specific process identification number (SPID). To return information on active processes, specify ACTIVE. ACTIVE excludes from the report processes that are waiting for the next command from the user.
Return Code Values

0 (success) or 1 (failure)

Result Sets
Column Data type Description
spid smallint The system process ID.
status nchar(30) The process status.
loginame nchar(128) The login name associated with the particular process.
hostname nchar(128) The host or computer name for each process.
blk char(5) The system process ID for the blocking process, if one exists. Otherwise, this column is zero.
dbname nchar(128) The database used by the process.
cmd nchar(16) The SQL Server command (Transact-SQL statement, SQL Server internal engine process, and so on) executing for the process.

Remarks

A blocking process (which may have an exclusive lock) is one that is holding resources that another process needs.

Permissions

Execute permissions default to the public role.

Examples
A. List all current processes

This example uses sp_who without parameters to report all current users. In this example, process ID 11 (a SELECT on a table) is blocked by process ID 10 (an uncommitted transaction).

USE master

EXEC sp_who

  

Here is the result set:

spid   status    loginame hostname  blk   dbname     cmd             
----- ---------  -------- --------- ----- ---------- ----------------
1     sleeping   sa                 0     master     MIRROR HANDLER  
2     sleeping   sa                 0     master     LAZY WRITER     
3     sleeping   sa                 0     master     CHECKPOINT SLEEP
4     sleeping   sa                 0     master     RA MANAGER      
10    sleeping   janetl   SEATTLE1  0     pubs       AWAITING COMMAND
11    runnable   stevenb  LONDON2   10    pubs       SELECT          

  

B. List a specific user’s process

This example shows how to view information about a single current user by login name.

USE master

EXEC sp_who 'janetl'

  

C. Display all active processes

USE master

EXEC sp_who 'active'

  

D. Display a specific process with process ID

USE master

EXEC sp_who '10' --specifies the process_id

  

See Also
KILL System Stored Procedures
sp_lock  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.