Overview

Adaptive Server allows you to create and manage multiple temporary databases in addition to the system tempdb, which was the only temporary database in the server in earlier versions of Adaptive Server.

Multiple temporary databases, also referred to as tempdbs, reduce contention on system catalogs and logs in the system tempdb. They allow you to:

The multiple temporary database feature is fully enabled for:

The tempdb database is the system-created temporary database. Before Adaptive Server version 12.5.0.3, tempdb was the only temporary database in the server. Temporary tables and work tables are created in tempdb.

Adaptive Server allows you to create multiple temporary databases, which you can then use to create temporary objects such as private temporary tables and work tables. Database administrators can bind—that is, create associations between—the “sa” login and applications to specific temporary databases or to the default group of temporary databases using sp_tempdb. The default group is a system-created group that always has at least the system tempdb as its member. You can add other temporary databases to this group.

NoteYou cannot explicitly bind objects to tempdb.

An application bound to the group can be assigned any temporary database from within the group in a round-robin fashion.

NoteUser groups and the default temporary database group are not related.

User-created temporary databases

User-created temporary databases are created by the user, typically the database administrator. These databases are usually created to minimize resource contention (such as system catalog and log contention) in the system tempdb. User-created temporary databases are very similar to the system tempdb in that they are:

All objects in a temporary database before a shutdown or crash are lost during recovery because temporary databases are overwritten with the model database. Those restrictions that apply to the system tempdb also apply to the user-created temporary databases. See “Rollback and recovery” for more information.

Unlike the system tempdb, you can drop user-created temporary databases.

Temporary databases and bindings

During login, sessions get assigned to a temporary database based on the existing bindings in effect:

The temporary database chosen for a session remains in effect for the duration of that session and never gets changed, regardless of any changes to the bindings.

Once a session is assigned a temporary database, all temporary objects created during that session are created in that temporary database. These objects are implicitly dropped when the session or server shuts down. Shareable temporary tables are implicitly dropped when the server shuts down.

NoteTemporary tables may be dropped explicitly by the session.

Server or shareable temporary tables continue to be created in the system tempdb if they are fully qualified as “tempdb..server_temptab” to include the database and table name. This is done to make sure that existing applications that pass information between sessions using shareable temporary tables continue to work. New applications, however, can use user-created tempdbs to create shareable temporary tables.

Private temp tables

Private temporary tables are created per session, and use the “#” symbol at the beginning of their names (for example, #pubs). They cannot be shared across sessions. These temporary tables and work tables reside in the session’s assigned temporary database. There are two types of private temp tables. They are also differentiated by their visible scope and how long they implicitly exist:

Applications can create shareable temporary tables in user-created temporary databases in exactly the same way that they create shareable temporary tables created in the system tempdb. Cooperating processes can communicate through these tables.

NoteProcedural temporary tables can also be explicitly dropped.

Stored procedures that create or access private temporary tables, do so in the temporary database assigned to the session.

Shareable temp tables

Shareable temporary tables can be created in user-created temporary databases as well as in the system tempdb. All shareable temporary tables can be shared across sessions and are implicitly dropped when the Server reboots.

NoteUnlike the system tempdb, user-created temporary databases can be dropped. Any applications that are dependent upon a dropped user-created temporary database will not work if shareable temp tables existed.