{"id":252,"date":"2007-01-29T13:36:01","date_gmt":"2007-01-29T12:36:01","guid":{"rendered":"http:\/\/www.galhano.com\/blog\/?p=252"},"modified":"2007-01-29T18:22:34","modified_gmt":"2007-01-29T17:22:34","slug":"sp_who","status":"publish","type":"post","link":"http:\/\/galhano.com\/blog\/?p=252","title":{"rendered":"sp_who"},"content":{"rendered":"<p>Provides information about current Microsoft\u00c2\u00ae SQL Server\u00e2\u201e\u00a2 users and processes. The information returned can be filtered to return only those processes that are not idle.<\/p>\n<h5>Syntax<\/h5>\n<p><strong>sp_who<\/strong> [[<strong>@login_name =<\/strong>] <strong>&#8216;<\/strong><em>login<\/em><strong>&#8216;<\/strong>]<\/p>\n<h5>Arguments<\/h5>\n<p>[<strong>@login_name =<\/strong>] <strong>&#8216;<\/strong><em>login<\/em><strong>&#8216;<\/strong><\/p>\n<p class=\"indent\">Is a user login name on SQL Server. <em>login<\/em> is <strong>sysname<\/strong>, with a default of NULL. If no name is specified, the procedure reports all active users of SQL Server. <em>login<\/em> can also be a specific process identification number (SPID). To return information on active processes, specify <strong>ACTIVE<\/strong>. <strong>ACTIVE<\/strong> excludes from the report processes that are waiting for the next command from the user.<\/p>\n<h5>Return Code Values<\/h5>\n<p>0 (success) or 1 (failure)<\/p>\n<h5>Result Sets<\/h5>\n<p><strong>sp_who<\/strong> returns a result set with the following information.<\/p>\n<p><a target=\"_blank\" title=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa260384(SQL.80).aspx\" href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa260384(SQL.80).aspx\">MSDN LINK<\/a><\/p>\n<p><!--more--><\/p>\n<h2>sp_who (T-SQL)<\/h2>\n<p>Provides information about current Microsoft\u00c2\u00ae SQL Server\u00e2\u201e\u00a2 users and processes. The information returned can be filtered to return only those processes that are not idle.<\/p>\n<h5>Syntax<\/h5>\n<p class=\"syntax\"><strong>sp_who<\/strong> [[<strong>@login_name =<\/strong>] <strong>&#8216;<\/strong><em>login<\/em><strong>&#8216;<\/strong>]<\/p>\n<h5>Arguments<\/h5>\n<dl>\n<dt>[<strong>@login_name =<\/strong>] <strong>&#8216;<\/strong><em>login<\/em><strong>&#8216;<\/strong><\/dt>\n<dd>Is a user login name on SQL Server. <em>login<\/em> is <strong>sysname<\/strong>, with a default of NULL. If no name is specified, the procedure reports all active users of SQL Server. <em>login<\/em> can also be a specific process identification number (SPID). To return information on active processes, specify <strong>ACTIVE<\/strong>. <strong>ACTIVE<\/strong> excludes from the report processes that are waiting for the next command from the user.<\/dd>\n<\/dl>\n<h5>Return Code Values<\/h5>\n<p>0 (success) or 1 (failure)<\/p>\n<h5>Result Sets<\/h5>\n<table width=\"479\" cellspacing=\"0\">\n<tr valign=\"top\">\n<th width=\"16%\" align=\"left\">Column<\/th>\n<th width=\"21%\" align=\"left\">Data type<\/th>\n<th width=\"63%\" align=\"left\">Description<\/th>\n<\/tr>\n<\/table>\n<h5>Remarks<\/h5>\n<p>A blocking process (which may have an exclusive lock) is one that is holding resources that another process needs.<\/p>\n<h5>Permissions<\/h5>\n<p>Execute permissions default to the <strong>public<\/strong> role.<\/p>\n<h5>Examples<\/h5>\n<h5>A.    List all current processes<\/h5>\n<p>This example uses <strong>sp_who<\/strong> 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).<\/p>\n<p class=\"ex\"><code>USE master<\/code><\/p>\n<p class=\"ex\"><code>EXEC sp_who<\/code><\/p>\n<p class=\"ex\"><strong><em><code>\u00c2 \u00c2 <\/code><\/em><\/strong><\/p>\n<p>Here is the result set:<\/p>\n<p class=\"ex\"><code>spid\u00c2 \u00c2  status\u00c2 \u00c2 \u00c2  loginame hostname\u00c2  blk\u00c2 \u00c2  dbname\u00c2 \u00c2 \u00c2 \u00c2  cmd<br \/>\n----- ---------\u00c2  -------- --------- ----- ---------- ----------------<br \/>\n1\u00c2 \u00c2 \u00c2 \u00c2  sleeping\u00c2 \u00c2  sa\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  0\u00c2 \u00c2 \u00c2 \u00c2  master\u00c2 \u00c2 \u00c2 \u00c2  MIRROR HANDLER<br \/>\n2\u00c2 \u00c2 \u00c2 \u00c2  sleeping\u00c2 \u00c2  sa\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  0\u00c2 \u00c2 \u00c2 \u00c2  master\u00c2 \u00c2 \u00c2 \u00c2  LAZY WRITER<br \/>\n3\u00c2 \u00c2 \u00c2 \u00c2  sleeping\u00c2 \u00c2  sa\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  0\u00c2 \u00c2 \u00c2 \u00c2  master\u00c2 \u00c2 \u00c2 \u00c2  CHECKPOINT SLEEP<br \/>\n4\u00c2 \u00c2 \u00c2 \u00c2  sleeping\u00c2 \u00c2  sa\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  0\u00c2 \u00c2 \u00c2 \u00c2  master\u00c2 \u00c2 \u00c2 \u00c2  RA MANAGER<br \/>\n10\u00c2 \u00c2 \u00c2  sleeping\u00c2 \u00c2  janetl\u00c2 \u00c2  SEATTLE1\u00c2  0\u00c2 \u00c2 \u00c2 \u00c2  pubs\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  AWAITING COMMAND<br \/>\n11\u00c2 \u00c2 \u00c2  runnable\u00c2 \u00c2  stevenb\u00c2  LONDON2\u00c2 \u00c2  10\u00c2 \u00c2 \u00c2  pubs\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  SELECT\u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2 \u00c2  <\/code><\/p>\n<p class=\"ex\"><strong><em><code>\u00c2 \u00c2 <\/code><\/em><\/strong><\/p>\n<h5>B.    List a specific user\u00e2\u20ac\u2122s process<\/h5>\n<p>This example shows how to view information about a single current user by login name.<\/p>\n<p class=\"ex\"><code>USE master<\/code><\/p>\n<p class=\"ex\"><code>EXEC sp_who &#039;janetl&#039;<\/code><\/p>\n<p class=\"ex\"><strong><em><code>\u00c2 \u00c2 <\/code><\/em><\/strong><\/p>\n<h5>C.    Display all active processes<\/h5>\n<p class=\"ex\"><code>USE master<\/code><\/p>\n<p class=\"ex\"><code>EXEC sp_who &#039;active&#039;<\/code><\/p>\n<p class=\"ex\"><strong><em><code>\u00c2 \u00c2 <\/code><\/em><\/strong><\/p>\n<h5>D.    Display a specific process with process ID<\/h5>\n<p class=\"ex\"><code>USE master<\/code><\/p>\n<p class=\"ex\"><code>EXEC sp_who &#039;10&#039; --specifies the process_id<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Provides information about current Microsoft\u00c2\u00ae SQL Server\u00e2\u201e\u00a2 users and processes. The information returned can be filtered to return only those processes that are not idle. Syntax sp_who [[@login_name =] &#8216;login&#8216;] Arguments [@login_name =] &#8216;login&#8216; Is a user login name on SQL Server. login is sysname, with a default of NULL. If no name is specified, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"close","ping_status":"close","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40,9],"tags":[],"class_list":["post-252","post","type-post","status-publish","format-standard","hentry","category-sql","category-sql-server","author-admin"],"_links":{"self":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252"}],"version-history":[{"count":0,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/252\/revisions"}],"wp:attachment":[{"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/galhano.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}