Last active
February 23, 2016 18:11
-
-
Save robsonalves/2d04495807c667c287cb to your computer and use it in GitHub Desktop.
Detach and attach via CMD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE MASTER; | |
GO | |
-- Take database in single user mode -- if you are facing errors | |
-- This may terminate your active transactions for database | |
ALTER DATABASE Piloto | |
SET SINGLE_USER | |
WITH ROLLBACK IMMEDIATE; | |
GO | |
-- Detach DB | |
EXEC MASTER.dbo.sp_detach_db @dbname = N'Piloto' | |
GO | |
-- Move MDF File from Loc1 to Loc 2 | |
-- Re-Attached DB | |
CREATE DATABASE [Piloto] ON | |
( FILENAME = N'H:\Data\Piloto.mdf' ), | |
( FILENAME = N'G:\Log\Piloto.ldf' ) | |
FOR ATTACH | |
GO | |
ALTER DATABASE Piloto | |
SET READ_COMMITTED_SNAPSHOT ON; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment