Great Article about TempDB from BrentOzar
www.brentozar.com/go/tempDB
www.brentozar.com/go/tempDB
Use Master
Go
Declare @dbname sysname
Set @dbname = 'databaseName'
Declare @spid intSelect @spid = min(spid) from master.dbo.sysprocesseswhere dbid = db_id(@dbname)
While @spid Is Not Null
Begin
Execute ('Kill ' + @spid)
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname) and spid > @spidEnd
USE [master]
ALTER DATABASE [DBname] SET SINGLE_USER WITH ROLLBACK IMMEDIATE --// Kills all connections and starts restore process
RESTORE DATABASE [DBName] FROM DISK = N'<backup location.BAK>'
WITH FILE = 1
,NOUNLOAD
,REPLACE
,STATS = 5
ALTER DATABASE [DBName] --//Sets back to multiuser
SET MULTI_USER
GO