Skip to content

Instantly share code, notes, and snippets.

@robsonalves
Last active February 23, 2016 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsonalves/2d04495807c667c287cb to your computer and use it in GitHub Desktop.
Save robsonalves/2d04495807c667c287cb to your computer and use it in GitHub Desktop.
Detach and attach via CMD
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