- When the drive is full and you are in a situation where you cannot extend that drive.
- Move tempdb to a separate drive to increase its performance.
This is a simple process and cannot be done by detaching and attaching the database, as we cannot attach or detach a system database.
Also we need to restart the SQL services.
Here is the process how we can move the tempdb to a new location.
Also we need to restart the SQL services.
Here is the process how we can move the tempdb to a new location.
- First get the list of tempdb files by using this query
- Then for each tempdb file that you need to move, execute statements like below
- Stop SQL Services
- Start SQL Services
- Verify the new Location
select name,physical_name from sys.master_files where DB_NAME(database_id)='tempdb'
select name,physical_name from sys.master_files where DB_NAME(database_id)='tempdb'
Alter Database tempdb modify file (NAME = 'tempdev' ,FILENAME = 'Drive:\Path\tempdb.mdf') -- Mention the new locationAlter Database tempdb modify file (NAME = 'templog' , FILENAME = 'Drive:\Path\templog.ldf') -- Mention the new location