Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
@@SPID (Transact-SQL)
Applies to: 👁 Image
SQL Server 👁 Image
Azure SQL Database 👁 Image
Azure SQL Managed Instance 👁 Image
Azure Synapse Analytics 👁 Image
Analytics Platform System (PDW) 👁 Image
SQL database in Microsoft Fabric
Returns the session ID of the current user process.
👁 Image
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's the result set.
ID Login Name User Name
------ ------------------------------ ------------------------------
54 SEATTLE\joanna dbo
Examples: Azure Synapse Analytics and Analytics Platform System (PDW)
This example returns the Azure Synapse Analytics 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';
See Also
Feedback
Was this page helpful?
