@@SPID (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![yes](media/yes.png)Azure SQL Data Warehouse ![yes](media/yes.png)Parallel Data Warehouse

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

Here is the result set.

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

Examples: [!INCLUDEssSDWfull] and [!INCLUDEssPDW]

This example returns the SQL Data Warehouse session ID, the SQL Data Warehouse SQL Server 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