Move SQL Server 2008 database files to a new folder location

前端 未结 5 672
长情又很酷
长情又很酷 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:13

    You forgot to mention the name of your database (is it "my"?).

    ALTER DATABASE my SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    
    ALTER DATABASE my SET OFFLINE;
    
    ALTER DATABASE my MODIFY FILE 
    (
       Name = my_Data,
       Filename = 'D:\DATA\my.MDF'
    );
    
    ALTER DATABASE my MODIFY FILE 
    (
       Name = my_Log, 
       Filename = 'D:\DATA\my_1.LDF'
    );
    

    Now here you must manually move the files from their current location to D:\Data\ (and remember to rename them manually if you changed them in the MODIFY FILE command) ... then you can bring the database back online:

    ALTER DATABASE my SET ONLINE;
    
    ALTER DATABASE my SET MULTI_USER;
    

    This assumes that the SQL Server service account has sufficient privileges on the D:\Data\ folder. If not you will receive errors at the SET ONLINE command.

提交回复
热议问题