tempdb_id

Description

The tempdb_id() reports the temporary database that a given session is assigned to. 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, then 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, execute:

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

Usage

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

Standards

Permissions

See also

Commands select