rename database SQL code example

Example 1: sql server rename database

ALTER DATABASE MyTestDatabase MODIFY NAME = MyTestDatabaseCopy ;

Example 2: rename table sql

ALTER TABLE STUDENTS  
RENAME TO ARTISTS;

Example 3: rename table sql server

USE AdventureWorks2012;   
GO  
EXEC sp_rename 'Sales.SalesTerritory', 'SalesTerr';

Example 4: alter database name script

USE master;  
GO  
ALTER DATABASE MyTestDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE MyTestDatabase MODIFY NAME = MyTestDatabaseCopy ;
GO  
ALTER DATABASE MyTestDatabaseCopy SET MULTI_USER
GO

Tags:

Sql Example