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: Get SQL Server Backup Statuses

$computername='sql01' function getSqlBackupInfo ($sqlInstanceName=$env:computername, $dbName){ [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") $location=if($sqlInstanceName.Contains("`\")){ "SQLSERVER:\SQL\$sqlInstanceName\Databases" }else{ "SQLSERVER:\SQL\$sqlInstanceName\DEFAULT\Databases" } function getPacificTime($time){ if($time){ [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($time,'Pacific…

SQL: Using PowerShell to Check if a Table, View, or Stored Procedure Exists

#Usage # set variables $sqlServer='sql-server04' $databaseName="Test_Database" $objectType='view' $objectName='[dbo].[Test_View]' $saCred=get-credential # Call function checkDatabaseObject $sqlServer $databaseName…

SQL: Use PowerShell to Validate if Database Exists

This function may be invoked remotely from a machine that has SQL-PS module installed. The…