TechNet
Export (0) Print
Expand All

@@SPID (Transact-SQL)

 

THIS TOPIC APPLIES TO: yesSQL Server (starting with 2008)yesAzure SQL DatabaseyesAzure SQL Data Warehouse yesParallel Data Warehouse

Returns the session ID of the current user process.

Topic link icon Transact-SQL Syntax Conventions

-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse  
  
@@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';  

Here is the result set.

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

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

Configuration Functions
sp_lock (Transact-SQL)
sp_who

Community Additions

ADD
Show:
© 2016 Microsoft