Create a temporary user database is an easy thing to do. Associate group of users to a temporary database can help you to reduce system tables contentions and increase your application availibility in case of tempdb full situation.
First, make sure you have created all necessary devices you need to create the temporary database. Devices can be created on rawdevices or filesystems.
In this example, we will create a temporary database of 4Gb on device named “tempdb_stats”, then we will bind a user named “userstats” to it.
- Create the tempdb that will be used by the login:
USE master
go
create temporary database tempdb_stats on tempdb_stats = 4000
go
USE tempdb_stats
go- Create the login that will use the tempdb
exec sp_addlogin 'userstats', 'xxxxxxxx', @defdb='master', @deflanguage='us_english'
go
exec sp_locklogin 'userstats', 'unlock'
go- Let’s bind the login to the tempdb:
sp_tempdb 'bind', 'lg', 'userstats', 'DB', 'tempdb_stats'
goThat’s it !





