T-SQL: How To Rename Database in Microsoft SQL Server

The T-SQL

USE master;  
GO  
ALTER DATABASE TEST_MSCRM SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE TEST_MSCRM MODIFY NAME = RENAMED_MSCRM;
GO  
ALTER DATABASE RENAMED_MSCRM SET MULTI_USER;
GO

Sample Output

Nonqualified transactions are being rolled back. Estimated rollback completion: 0%.
Nonqualified transactions are being rolled back. Estimated rollback completion: 100%.
The database name 'RENAMED_MSCRM' has been set.

Completion time: 2012-10-29T16:09:11.0019350-07:00

Leave a Reply

Your email address will not be published. Required fields are marked *