USE MASTER;
GO
-- Take database in single user mode -- if you are facing errors -- This may terminate your active transactions for database
ALTER DATABASE xxDBNamexx
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
-- Detach DB
EXEC MASTER.dbo.sp_detach_db @dbname = N'TestDB' GO
Now move the files from loc1 to loc2. You can now reattach the files with new locations
GO
-- Take database in single user mode -- if you are facing errors -- This may terminate your active transactions for database
ALTER DATABASE xxDBNamexx
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
-- Detach DB
EXEC MASTER.dbo.sp_detach_db @dbname = N'TestDB' GO
Now move the files from loc1 to loc2. You can now reattach the files with new locations
-- Move MDF File from Loc1 to Loc 2-- Re-Attached DBCREATE DATABASE [TestDB] ON( FILENAME = N'F:\loc2\TestDB.mdf' ),( FILENAME = N'F:\loc2\TestDB_log.ldf' )FOR ATTACHGO
No comments:
Post a Comment