Posted On October 29, 2021

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

kimconnect 0 comments
blog.KimConnect.com >> Database >> 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 *

Related Post

PowerShell: Obtaining SQL Database Default Paths

# This function returns an array of 3 string values reflecting default Data, Log, and…

MS SQL Maintenance

Below is a list of practical SQL snippets to administer Microsoft databases: -- Shrink Database:…

SQL: Backup Database and Purge It From SQL Server

/* Make a Final Backup of Database, Purge Its Backup and Restore History, and Remove…