tempdb_id

Description

Reports the temporary database to which a given session is assigned. The input of the tempdb_id function is a server process ID, and its output is the temporary database to which the process is assigned. If you do not provide a server process, tempdb_id reports the dbid of the temporary database assigned to the current process.

Syntax

tempdb_id()

Examples

Example 1

Finds all the server processes that are assigned to a given temporary database:

select spid from master..sysprocesses 
    where tempdb_id(spid) = db_id("tempdatabase")

Usage

select tempdb_id gives the same result as select @@tempdbid.

See also

Commands select