Posted by: Rasikananda Das | November 28, 2016

How to move TempDB files to another location

First of all lets use sp_helpfile on tempdb database to get the list of all the tempdb files there are.


-- Shows all tempdb files
USE tempdb
GO
EXEC sp_helpfile
GO

Once we know all the tempdb files we can use the following query to move the files to new location. Remember tempdb gets created every time SQL Server is restarted so you won’t see tempdb files in new location until SQL Server has been restarted.


-- Move to C:\ 
USE master
GO
ALTER DATABASE tempdb 
MODIFY FILE (NAME = tempdev, FILENAME = 'C:\tempdb2005.mdf')
GO
ALTER DATABASE tempdb 
MODIFY FILE (NAME = templog, FILENAME = 'C:\tempdb2005.ldf')
GO
ALTER DATABASE temp2 
MODIFY FILE (NAME = temp2, FILENAME = 'C:\tempdb2005.ndf')
GO


Leave a comment

Categories