2

I'm trying to relocate system databases files. I managed to do that with the tempdb database, but I'm stuck with msdb.

When I run:

SELECT name, physical_name AS current_file_location
FROM sys.master_files
WHERE database_id IN DB_ID('msdb')

it shows that the logical names are 'MSDBData' and 'MSDBLog'. Then when I run below mention TSQL query

alter database tempdb modify file (name = MSDBData, filename = 'C:\Data\MSDBData.mdf')

I am getting the following error: MODIFY FILE failed. File 'MSDBData' does not exist.

MS Sql 2008 R2 server version: 10.50.1600

Md Haidar Ali Khan
6,5339 gold badges40 silver badges62 bronze badges
asked Oct 29, 2015 at 9:29
1
  • alter database tempdb or msdb? Commented Oct 29, 2015 at 10:02

1 Answer 1

1

First, you should use:

... WHERE DB_NAME(database_id) IN ('msdb', 'xxx', ...)

or

... WHERE database_id = DB_ID('msdb')

Syntax for ALTER DATABASE is:

ALTER DATABASE database_name MODIFY FILE ( NAME = logical_name , FILENAME = 'new_path\os_file_name' )

In your case values are as follow:

  • database_name = MSDB
  • logical_name = MSDBData (or MSDBLog)
  • 'new_path\os_file_name' = 'C:\Data\MSDBData.mdf'

Then you can follow this procedure for MSDB:

  • execute ALTER DATABASE MSDB MODIFY FILE ( NAME = MSDBData, FILENAME = '...new path' )
  • and/or execute ALTER DATABASE MSDB MODIFY FILE ( NAME = MSDBLog, FILENAME = '...new path' )
  • stop SQL Server service
  • Move MSDBData and/or MSDBLog to their new location
  • Start SQL Server service
  • Check new file location

    SELECT name, physical_name AS current_file_location
    FROM sys.master_files
    WHERE database_id = DB_ID('msdb')
    

You must replace value such as MSDB, file location, file name with the correct values for your environment.

answered Oct 29, 2015 at 10:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.