| title | @@SPID (Transact-SQL) | |||||||
|---|---|---|---|---|---|---|---|---|
| description | @@SPID (Transact-SQL) | |||||||
| author | MikeRayMSFT | |||||||
| ms.author | mikeray | |||||||
| ms.date | 09/18/2017 | |||||||
| ms.service | sql | |||||||
| ms.subservice | t-sql | |||||||
| ms.topic | reference | |||||||
| ms.custom |
|
|||||||
| f1_keywords |
|
|||||||
| helpviewer_keywords |
|
|||||||
| dev_langs |
|
|||||||
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricsqldb]
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
@@SPID
smallint
@@SPID can be used to identify the current user process in the output of sp_who.
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';