Friday 19 April 2013

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.

No comments:

Post a Comment