-- You don't want to be in the database you are trying to detach
USE Master
GO
-- Optional step to drop all active connections and roll back their work
ALTER DATABASE DatabaseName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
-- Perform the detach
EXEC sp_detach_db test
GO
CREATE DATABASE CORD_DB_1525
ON (FILENAME = 'E:\External_HD\DATA\Test.mdf'), -- Main Data File .mdf
(FILENAME = 'E:\External_HD\DATA\Test_log.ldf'), -- Log file .ldf
(FILENAME = 'E:\External_HD\DATA\Test.ndf') -- Optional - any secondary data files
FOR ATTACH
GO
USE Master
GO
-- Optional step to drop all active connections and roll back their work
ALTER DATABASE DatabaseName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
-- Perform the detach
EXEC sp_detach_db test
GO
CREATE DATABASE CORD_DB_1525
ON (FILENAME = 'E:\External_HD\DATA\Test.mdf'), -- Main Data File .mdf
(FILENAME = 'E:\External_HD\DATA\Test_log.ldf'), -- Log file .ldf
(FILENAME = 'E:\External_HD\DATA\Test.ndf') -- Optional - any secondary data files
FOR ATTACH
GO