Move SQL Server 2008 database files to a new folder location

前端 未结 5 676
长情又很酷
长情又很酷 2020-12-12 11:32

Logical Name

  • my_Data
  • my_Log

Path:

  • C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLS
5条回答
  •  感情败类
    2020-12-12 12:07

    Some notes to complement the ALTER DATABASE process:

    1) You can obtain a full list of databases with logical names and full paths of MDF and LDF files:

       USE master SELECT name, physical_name FROM sys.master_files
    

    2) You can move manually the files with CMD move command:

    Move "Source" "Destination"

    Example:

    md "D:\MSSQLData"
    Move "C:\test\SYSADMIT-DB.mdf" "D:\MSSQLData\SYSADMIT-DB_Data.mdf"
    Move "C:\test\SYSADMIT-DB_log.ldf" "D:\MSSQLData\SYSADMIT-DB_log.ldf"
    

    3) You should change the default database path for new databases creation. The default path is obtained from the Windows registry.

    You can also change with T-SQL, for example, to set default destination to: D:\MSSQLData

    USE [master]
    
    GO
    
    EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultData', REG_SZ, N'D:\MSSQLData'
    
    GO
    
    EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft\MSSQLServer\MSSQLServer', N'DefaultLog', REG_SZ, N'D:\MSSQLData'
    
    GO
    

    Extracted from: http://www.sysadmit.com/2016/08/mover-base-de-datos-sql-server-a-otro-disco.html

提交回复
热议问题