Thursday, April 23, 2020

SQL - Rename Database Using SQL Command


To rename a SQL Server database by placing it in single-user mode

Use the following steps to rename a SQL Server database using T-SQL in SQL Server Management Studio including the steps to place the database in single-user mode and, after the rename, place the database back in multi-user mode.


USE master
ALTER DATABASE [DBDGL_TEST] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [DBDGL_TEST] MODIFY NAME = [DBDGL_Flight]
ALTER DATABASE [DBDGL_Flight] SET MULTI_USER

No comments:

Post a Comment