SQL Server @@SPID
SQL Server @@SPID is a SQL function in the SQL Server Specific category. SQL Server: returns the session ID (SPID) of the current process. Useful for identifying your session. The syntax is SELECT @@SPID;. It accepts see syntax. It returns session SPID. A typical example: SELECT @@SPID AS my_session_id; -- Returns: 62 -- Use in dynamic SQL error messages: RAISERROR('Process %d encountered an error', 16, 1, @@SPID); -- Kill your own session (rarely useful): -- KILL @@SPID; -- Would disconnect yourself -- List all sessions: SELECT session_id, login_name, status, host_name, program_name FROM sys.dm_exec_sessions WHERE is_user_process = 1; -- Find blocking sessions: SELECT blocking_session_id, session_id, wait_type, wait_resource FROM sys.dm_exec_requests WHERE blocking_session_id > 0; A close relative is OUTPUT Clause, which sQL Server: returns values from DML statements (like PostgreSQL RETURNING). A close relative is STUFF(), which sQL Server: deletes a specified length of characters from a string and inserts another string at the start position.