How to rename SQL Server database?

3740 pts.
Tags:
SQL Server
I am working on SQL Server 2014 and I have some older projects where my database name is different and same database I am using in my other projects. So how can I change my database name?
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

Use this

USE master;

GO

ALTER DATABASE <oldname>

Modify Name = <newname> ;

GO

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    Alter database <oldDBName> modify name = <newName>
    132,270 pointsBadges:
    report
  • AjitK29
    -- Replace all MyDBs with the name of the DB you want to change its name
    USE [MyDB];
    -- Changing Physical names and paths
    -- Replace all NewMyDB with the new name you want to set for the DB
    -- Replace 'C:\...\NewMyDB.mdf' with full path of new DB file to be used
    ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB ', FILENAME = 'C:\...\NewMyDB.mdf');
    -- Replace 'C:\...\NewMyDB_log.ldf' with full path of new DB log file to be used
    ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB _log', FILENAME = 'C:\...\NewMyDB_log.ldf');
    -- Changing logical names
    ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB, NEWNAME = NewMyDB);
    ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB _log, NEWNAME = NewMyDB_log);

    Reference:
    http://www.codeproject.com/Tips/345942/Rename-a-Database-and-its-MDF-and-LDF-files-in-SQL

    2,545 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: