Created
October 22, 2022 12:34
-
-
Save petesql/9f43f86145f4971b2cdffd07ba293952 to your computer and use it in GitHub Desktop.
Generate script, alter database move tempdb in SQL Server
This file contains 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
-- generate script, alter database move temp db | |
SELECT 'ALTER DATABASE tempdb MODIFY FILE (NAME = [' + f.name + '],' | |
+ ' FILENAME = ''D:\mssql_temp_db\' + f.name | |
+ CASE WHEN f.type = 1 THEN '.ldf' ELSE '.mdf' END + ''');' | |
FROM sys.master_files f | |
WHERE f.database_id = DB_ID(N'tempdb'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My blog post that includes the use of this script: Move TempDB in SQL Server, 20/10/2022