Tuesday, February 26, 2019

Sql Server - Create a copy of database and Renaming it

Steps to attach a database with different name:

  1. Detach database from local PC
  2. Copy the mdf and ldf files and rename them.
  3. Copy\Move the files to the server directory where the original Database is stored.
  4. Use the below code
USE [master]
GO
CREATE DATABASE [example_db] ON ( FILENAME = N'D:\Data\example_db.mdf' ),
( FILENAME = N'E:\Logs\example_db_log.ldf' )FOR ATTACH
GO


you can also copy by using the Sql-server Management studio:

  • go to database and tasks->Copy Database
  • Select the source and destination server (same if you wants to make a copy on the same server)
  • change the destination database name to required.
  • Done

1 comment:

monalisha biswal said...

I always looking for this kind of post which is really very impressive and well maintained. I found this post like that. Thanks for sharing and keep updating.
Server Management Company in Delhi