53GB

How To Generate the Script to move the Temp db files in SQL Server



How To Generate the Script to move the Temp db files in SQL Server

T SQL Script to Generate the TEMP db move
============================
USE master;
GO
DECLARE @newfilepath NVARCHAR(260) = ‘E:datanew’; — Update this with your new file path

DECLARE @stmt NVARCHAR(MAX) = ”;
SELECT @stmt += ‘ALTER DATABASE tempdb MODIFY FILE (NAME = ‘ + name + ‘, FILENAME = ”’ + @newfilepath + REPLACE(physical_name, ‘C:Program FilesMicrosoft SQL ServerMSSQL15.SQLHYD2019MSSQLDATA’, ”) + ”’) ‘ + CHAR(13)
FROM tempdb.sys.database_files;
PRINT @stmt
=============================

Exit mobile version