sp_who

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

sp_who returns a result set with the following information.

MSDN LINK

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

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *