Skip to content

Latest commit

 

History

History
83 lines (67 loc) · 2.8 KB

File metadata and controls

83 lines (67 loc) · 2.8 KB

title: "@@SPID (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "09/18/2017" ms.prod: "sql" ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.service: "" ms.component: "t-sql|functions" ms.reviewer: "" ms.suite: "sql" ms.technology:

  • "database-engine" ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords:
  • "@@SPID"
  • "@@SPID_TSQL" dev_langs:
  • "TSQL" helpviewer_keywords:
  • "@@SPID function"
  • "session_id"
  • "server process IDs [SQL Server]"
  • "IDs [SQL Server], user processes"
  • "SPID"
  • "session IDs [SQL Server]"
  • "process ID of current user process" ms.assetid: df955d32-8194-438e-abee-387eebebcbb7 caps.latest.revision: 39 author: "edmacauley" ms.author: "edmaca" manager: "craigg" ms.workload: "On Demand" monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions"

@@SPID (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all-md]

Returns the session ID of the current user process.

Topic link icon Transact-SQL Syntax Conventions

Syntax

@@SPID  

Return Types

smallint

Remarks

@@SPID can be used to identify the current user process in the output of sp_who.

Examples

This example returns the session ID, login name, and user name for the current user process.

SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name';  

[!INCLUDEssResult]

ID     Login Name                     User Name                       
------ ------------------------------ ------------------------------  
54     SEATTLE\joanna                 dbo                             

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

This example returns the [!INCLUDEssDW] session ID, the [!INCLUDEssNoVersion] Control node session ID, login name, and user name for the current user process.

SELECT SESSION_ID() AS ID, @@SPID AS 'Control ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name';  

See Also

Configuration Functions
sp_lock (Transact-SQL)
sp_who