Select * from SourceDB..sysfiles
ALTER DATABASE SourceDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE SourceDB SET MULTI_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE SourceDB MODIFY Name = TargetDB
ALTER DATABASE TargetDB MODIFY FILE (NAME=N'SourceDB', NEWNAME=N'TargetDB')
ALTER DATABASE TargetDB MODIFY FILE (NAME=N'SourceDB_log', NEWNAME=N'TargetDB_log')
USE [master]
ALTER DATABASE TargetDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC master.dbo.sp_detach_db @dbname = N'TargetDB'
Rename Physical files as per the ‘TargetDB’
USE [master]
CREATE DATABASE TargetDB ON
( FILENAME = N'F:\DataFiiles\TargetDB_data.mdf'),
( FILENAME = N'G:\LogFiles\TargetDB_log.ldf')
FOR ATTACH
select * from TargetDB..sysfiles
No comments: