How to rename a database in SQL Server

To rename a database in SQL Server use this code:

USE master;
GO
ALTER DATABASE old_database_name
Modify Name = new_database_name;
GO

To rename a database using SQL Server Management Studio:

Right-click the database you want to rename, and then click Rename:

Enter the new database name, and then click OK.

Make sure that no one is using the database, and then set the database to single-user mode before renaming the database.

System databases cannot be renamed.

When a database is renamed, filegroup names and file names (.mdf, .ldf) are not changed.

To see how to rename logical and physical names of database files in SQL Server read this blog post:
Rename logical and physical names of database files in SQL Server

It is recommended to back up the master database after you rename any database.

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">