[TSQL|SQLSERVER|MSSQL数据库] 将数据库文件与日志附加到数据库引擎,以及转移数据库文件位置

时间:2024-11-10 15:03:38
附加:

USE [master]
GO
CREATE DATABASE [database_name] ON
( FILENAME = N'C:\Data\<database name>.mdf' ),
( FILENAME = N'D:\Data\<database name>.ldf' )
FOR ATTACH ;
GO 转移:
USE master;
ALTER DATABASE foo
MODIFY FILE (name='DB_Data1',filename='X:\NewDBFile\DB_Data1.mdf'); --Filename is new location
ALTER DATABASE foo SET OFFLINE WITH ROLLBACK IMMEDIATE;