sp_tempdb allows users to:
Create and manage temporary database groups.
Bind users or applications to the default or other temporary database group or to a specific local temporary database.
Manage bindings to local temporary databases and temporary database groups.
These bindings are stored in the sysattributes table in master database.
sp_tempdb provides the binding interface for maintaining bindings in sysattributes that are related to the multiple temporary database.
sp_tempdb [ [ { “create” | “drop” } , “groupname” ] | [ { “add” | “remove” } , “tempdbname”, “groupname” ] | [ { “bind”, “objtype”, “objname”, “bindtype”, “bindobj” [, “scope”, “hardness” ] } | { “unbind”, “objtype”, “objname” [, “scope” ] “instance_name”} ] | [ “unbindall_db”, “tempdbname” ] | [ show [, "all" | "gr" | "db" | "login" | "app" [, “name” ] ] | [ who, “dbname”] [ help ] ]
login_name (or LG)
application_name (or AP)
Values are not case-sensitive.
group (or GR)
database (or DB)
Values are not case-sensitive.
When you set the value to soft, such a failure results in the assignment of a temporary database from the default group or a local system temporary database.
Existing assignments to active sessions are not affected by this operation.
all or no argument – displays the default temporary database group, all database-to-group memberships, and all login and application bindings.
gr – displays the default temporary database group. sp_tempdb show displays all temporary databases bound to the default temporary database group whether you specify “default” for the name option or not.
db – displays all databases and temporary databases to group memberships. If you provide name, then only the database to group memberships for the database name are printed.
login – displays all login bindings where login is not NULL. If you provide name, then only the bindings for the login name are printed.
app – displays all bindings where the application is not NULL. If you provide name, then the bindings for the application name are printed.
dbname – is the name of a temporary database. If you provide a nontemporary database name for dbname, sp_tempdb who executes, but does not report any active sessions bound to it.
If system_view is set to cluster, all active sessions of the cluster are examined. If system_view is set to instance, sessions that are active on the current instance are examined
This command may be executed from any instance in the cluster.
sp_tempdb "add", "mytempdb1", "default"
sp_tempdb "remove", "mytempdb1", "default"
sp_tempdb "bind", "lg", "sa", "GR", "default"
The value for objtype in this example is login_name. You can substitute login_name with lg or LG.
The value for bindtype in this example is group. You can substitute group with gr or GR.
sp_tempdb "bind", "lg", "sa", "DB", "mytempdb1"
The value for bindtype in this example is database. You can substitute database with db or DB.
sp_tempdb "bind", "ap", "isql", "DB", "mytempdb1"
The value for objtype in this example is application_name. You can substitute application_name with ap or AP.
sp_tempdb "bind", "ap", "isql", "GR", "default"
sp_tempdb "unbind", "lg", "sa"
sp_tempdb "unbind", "ap", "isql"
sp_tempdb "unbindall_db", "mytempdb1"
sp_tempdb show
Temporary Database Groups ------------------------------- default Database GroupName ------------------------------- ---------------- tempdb default mytempdb default mytempdb1 default mytempdb2 default mytempdb3 default Login Application Group Database Hardness ------- ------------- -------- ----------- -------- NULL isql default NULL SOFT sa NULL NULL mytempdb3 HARD
sp_tempdb show, "gr"
Temporary Database Groups ------------------------------- default
sp_tempdb show, "gr", "default"Member Databases ------------------------------- tempdb mytempdb mytempdb1 mytempdb2 mytempdb3
sp_tempdb show, "db"
Database Group --------------------- ---------------- tempdb default mytempdb default mytempdb1 default mytempdb2 default mytempdb3 default
sp_tempdb show, "db", "mytempdb1"
Database Group --------------------- ---------------- mytempdb1 default
sp_tempdb show, "login"
Login Application Group Database Hardness ------- ------------- ------- ----------- -------- sa NULL NULL mytempdb3 HARD
sp_tempdb who, "tempdb"
spid loginame ------ ------------------------------ 2 NULL 3 NULL 4 NULL 5 NULL 6 NULL 7 NULL 8 NULL
sp_tempdb who, "mytempdb3"
spid loginame ------ ------------------------------ 17 sa
sp_tempdb help
Usage: sp_tempdb 'help' sp_tempdb 'create', <groupname> sp_tempdb 'drop', <groupname> sp_tempdb 'add', <tempdbname>, <groupname> sp_tempdb 'remove', <tempdbname>, <groupname> sp_tempdb 'bind', <objtype>, <objname>, <bindtype>, <bindobj>, <scope>, <hardness> sp_tempdb 'unbind', <objtype>, <objname>, <scope> sp_tempdb 'unbindall_db', <tempdbname> sp_tempdb 'show', <command>, <name> sp_tempdb 'who', <dbname> <objtype> = ['LG' ('login_name') | 'AP' ('application_name')]; <bindtype> =['GR' ('group') | 'DB' ('database')] <hardness> = ['hard' | 'soft'] <command> = ['all' | 'gr' | 'db' | 'login' | 'app']
create temporary database mytempdb ------------- CREATE DATABASE: allocating 1536 logical pages (3.0 megabytes) on disk 'master'.| create temporary database mytempdb1 ---------- CREATE DATABASE: allocating 1536 logical pages (3.0 megabytes) on disk 'master'. sp_tempdb 'add', mytempdb,'default' ------------ (return status = 0 sp_tempdb show, db ------------- Database Group -------- tempdb default mytempdb default mytempdb1 (3 rows affected) (return status = 0)
sp_tempdb 'show'
sp_tempdb 'who', tempdbname
In SAP ASE versions 15.0 and above, you can obtain the same output by executing sp_who.
Must be a valid identifier
Cannot already exist
Upgrade using the SAP ASE server containing this feature, or
Create a new master device.
sp_tempdb create, "default"
An error message displays if you attempt to create a default group that already exists.
To add a temporary database to the default temporary database group, both the temporary database and the group name must already exist. When you use sp_tempdb add to add a tempdbname to a set of databases that are members of the default temporary database group, tempdbname becomes available for round-robin assignment from within that group.
User-created temporary databases need not belong to the default temporary database group. The system tempdb is implicitly a member of the default group.
If you try to add a temporary database to the default temporary database group when it is already a part of that group, you get an error message, and no changes take place in sysattributes.
The permission checks for sp_tempdb differ based on your granular permissions settings.
Setting | Description |
---|---|
Enabled | With granular permissions enabled, you must be a user with manage server privilege. |
Disabled | With granular permissions disabled, you must be a user with sa_role. |
Values in event and extrainfo columns from the sysaudits table are:
Information | Values |
---|---|
Event | 38 |
Audit option | exec_procedure |
Command or access audited | Execution of a procedure |
Information in extrainfo |
|