locked
How To Rename My Database RRS feed

  • Question

  • User2033107836 posted

    Hello 

    I Have One Database For Example ShoppingApp

    I have This SQL DB In Three Clients

    Now Each client has same and different Table and store procedure

    If i want to work in production server then I have to copy and replace each DB 

    So i what i did is i change name of DB and paste it in DATA folder and i click attach im getting this error

    cannot attach a database with the same name as an existing database

    for example i want like this below

    ShoppingApp_Aclient

    ShoppingApp_Bclient

    ShoppingApp_Cclient

    How To do so..?

    I want this all 3 db to be attach in my pc to use.

    How to do so using SQL Server 2008 R2

    Thanking You

    Thursday, November 9, 2017 6:03 AM

Answers

  • User347430248 posted

    Hi asp.ambur,

    you can follow the steps below.

    To rename a database

    1. Connect to the  Database Engine. 

    2. From the Standard bar, click New Query

    3. Copy and paste the following example into the query window and click Execute. This example changes the name of the AdventureWorks2012

      database to Northwind.

    USE master;  
    GO  
    ALTER DATABASE AdventureWorks2012  
    Modify Name = Northwind ;  
    GO  

    Note : - Requires ALTER permission on the database. 

    Reference:

     Rename a Database

    by this way you can rename the original database.

    but if you don't want to rename the original database then you can try to use backup and restore and copy the database with new name.

    Example:

    BACKUP DATABASE AdventureWorks2012   
       TO AdventureWorksBackups ;  
    
    RESTORE FILELISTONLY   
       FROM AdventureWorksBackups ;  
    
    RESTORE DATABASE TestDB   
       FROM AdventureWorksBackups   
       WITH MOVE 'AdventureWorks2012_Data' TO 'C:\MySQLServer\testdb.mdf',  
       MOVE 'AdventureWorks2012_Log' TO 'C:\MySQLServer\testdb.ldf';  
    GO  

    Copying a database using BACKUP and RESTORE

    Regards

    Deepak

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, November 9, 2017 6:38 AM