2/05/2012

How to Change a Database Name

If you need to change your created database name you can use the following method:

The first line of the code is for forcing other users to log off from the database. It is impossible to change database name when someone is using it.
ALTER DATABASE OldName SET SINGLE_USER WITH ROLLBACK IMMEDIATE

We will use sp_renamedb system stored procedure
USE OldName
EXEC sp_renamedb N' OldName', N'NewName'
ALTER DATABASE NewName SET MULTI_USER

There are also different ways of changing db name. First line of the above code is vital for all solutions.
Source:

No comments:

Post a Comment