Alter (Rename) SQL Server Database using Query or Management Studio

  Total Views : 545
  Comments : 0
 
  Keywords : How to change or rename database in sql server using query or management studio, Change database name in sql server using query or management studio, SQL rename statement to change database

Here we will learn how to change or rename or alter databases in sql server using query or script or management studio.

SQL Server ALTER / Rename Database using Query or Management Studio

To alter or rename or change name of SQL database we have two different methods one is using Query and another one is directly using SQL Server Management Studio

Using Query to ALTER / Rename SQL Database

By using “ALTER Database” statement we can change name of SQL database. Generally to alter or rename database in SQL our syntax will be like as shown below

Syntax to ALTER / Rename SQL Database using Query

We have two ways to change name of database in SQL using query those are

Using ALTER DATABASE SQL statement

Following is the syntax to alter or change sql database using ALTER Database statement

  

ALTER DATABASE olddbname MODIFY NAME= newdbname

Using EXEC SP_RENAMEDB SQL statement

Following is the syntax to change or rename sql database using EXEC sp_renamedb statement

 

EXEC sp_renamedb'olddbname', 'newdbname'

Here “olddbname” means name of the present database and “newdbname” means its new name for database

Examples to ALTER / Rename SQL Database

The following SQL statements will rename or change database name from “sqltutorialexamples” to “sqltutorialexample”. 

Example1

Following is the example to alter database name using ALTER DATABASE statement in sql server

  

ALTER DATABASE sqltutorialexamples MODIFY NAME= sqltutorialexample

Example2

Following is the example rename or change database name using EXEC sp_renamedb statement in sql server

  

EXEC sp_renamedb'sqltutorialexamples', 'sqltutorialexample'

Refresh your sql database section and check for database with new name that would be like as shown below

 

After renaming sql database using alter and rename statements in sql server

ALTER / Rename SQL Database using SQL Server Management Studio

To change database name open SQL Server Management Studio --> Select your database in Databases section --> Right click and Select Rename Database like as shown below  

 

to change database name in sql server right click on respective database and select rename

 

If you are getting any problem to rename database by using SQL management studio might be that problem because of already another process or application using database with same name to fix this problem try to restart SQL Server running service it will abort all the applications or services which using this database.

 

To restart service Search for Services à Select SQL Server à Right click Restart Service like as shown below

 

Restart sql server service in services section to rename database in sql server

 

 Once you restart service now right click on your database --> select Rename Database and change name. Once we rename database that will be like as shown below. Here we renamed database “sqltutorialexamples” to “sqltutorialexample

 

After renaming sql database using alter and rename statements in sql server

 Comments (0)

Be the first to give your valuable feedback

Leave a comment

  • Default Tutlane User