Pages

Saturday, September 27, 2008

Rename Database

In next couple of posts i will explain about some very usefull stored procedures in SQL Server.

This stored procedure is to rename the database from old names to new name. Microsoft is planning to remove this from future releases and also suggesting to use ALTER DATABASE command to implement the similar functionality.

Let’s look at the sample example

USE MASTER;
GO
CREATE DATABASE BANK_DB;
GO
EXEC SP_RENAMEDB N'BANK_DB', N'INVESTMENT_BANK_DB';
GO
SELECT NAME, DATABASE_ID, MODIFIED_DATE
FROM SYS.DATABASES
WHERE NAME = N'INVESTMENT_BANK_DB';
GO


We are creating a Database name called BANK_DB and then later we are modifying/renaming it to INVESTMENT_BANK_DB.

Query the SYS.DATABASES table to see whether it’s modified or not.

No comments: