SQL @@SPID

SQL @@SPID is one of the Configuration Functions, which will return the session ID that is currently used. The syntax behind this is

@@SPID

SQL @@SPID Example

The below code snippet will show the @@SPID and the respective login name that is currently being used.

SELECT @@SPID AS 'SP ID', 
       SYSTEM_USER AS 'Login Name', 
       USER AS 'User Name';
SP ID Example 1

Let us use another SQL Server login to enter into Management Studio. Now, you can see that it is displaying a different @@SPID and login name.

Login Name and user name 2

If you don’t know the list of available users and their IDs, then use the sp_who system stored procedure.

SQL @@SPID 3
Categories SQL