Created
December 19, 2025 16:15
-
-
Save ghotz/99899709e9d36b1f0586683de277a29e to your computer and use it in GitHub Desktop.
Move all tempdb files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| DECLARE @original_path sysname = N'E:\SQLServer\MSSQL15.SQL2022\MSSQL\DATA'; | |
| DECLARE @destination_path sysname = N'E:\SQLServer\MSSQL16.SQL2022\MSSQL\DATA'; | |
| DECLARE @sqlcmd nvarchar(max) = ( | |
| SELECT | |
| N'ALTER DATABASE [tempdb]' | |
| + N' MODIFY FILE (NAME = [' + [name] + ']' | |
| + N', FILENAME = ''' + REPLACE(physical_name, @original_path, @destination_path) + ''');' | |
| + CHAR(10) | |
| FROM sys.master_files | |
| WHERE [database_id] = DB_ID('tempdb') | |
| FOR XML PATH('')) | |
| PRINT @sqlcmd | |
| --EXEC(@sqlcmd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment