How to attach databases with the same name on the server

  • Hi , I have database saying DB1 on the production server, when i take a backup of my production db n attaching to my devserver, it is giving me errors.So i am copying over the mdf,ldf files and attaching them.But when i need a new copy of the DB1 , i have to detach the old version of DB1 it is saying i cannot attach 2 databases of same name eventhough i am renaming the mdf,ldf files.Please suggest me how can i retain the old DB1 on dev server and attach a new version of DB1.

  • when you resotre, or when you attach, you have the option to change the database name; it would fail of course if there is already a database with that name;

    if you are attaching, just change the name here:

    or in TSQL:

    USE [master]

    GO

    CREATE DATABASE [NewDatabaseName] ON

    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\SandBox.mdf' ),

    ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\SandBox_log.LDF' )

    FOR ATTACH

    GO

    here's where you change the name when selecting a backup file:

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks, will try it and let you know the results. Thanks for the answer

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply