Skip to content

Latest commit

 

History

History
74 lines (57 loc) · 2.6 KB

spid-transact-sql.md

File metadata and controls

74 lines (57 loc) · 2.6 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
@@SPID (Transact-SQL)
@@SPID (Transact-SQL)
MikeRayMSFT
mikeray
09/18/2017
sql
t-sql
reference
@@SPID
@@SPID_TSQL
@@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
TSQL
>= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || >= sql-server-linux-2017 || = azuresqldb-mi-current

@@SPID (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw]

Returns the session ID of the current user process.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

@@SPID  

[!INCLUDEsql-server-tsql-previous-offline-documentation]

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: [!INCLUDEssazuresynapse-md] and [!INCLUDEssPDW]

This example returns the [!INCLUDEssazuresynapse-md] 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