![]() USE master ĪLTER DATABASE MyTestDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE ĪLTER DATABASE MyTestDatabase MODIFY NAME = MyTestDatabaseCopy ĪLTER DATABASE MyTestDatabaseCopy SET MULTI_USER This will cause all incomplete transactions to be rolled back and any other connections to the MyTestDatabase database to be immediately disconnected. To quickly obtain exclusive access, the code sample uses the termination option WITH ROLLBACK IMMEDIATE. ![]() ![]() This example changes the name of the MyTestDatabase database to MyTestDatabaseCopy. Copy and paste the following example into the query window and select Execute.Connect to the master database for your instance.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 Transact-SQL To rename a SQL Server database by placing it in single-user mode Refresh the database list in Object Explorer. If the database was your default database, see Reset your default database after rename. In Object Explorer, expand Databases, right-click the database to rename, and then select Rename.Įnter the new database name, and then select OK If you are using SQL Server, you can set the database to single-user mode to close any open connections and prevent other users from connecting while you are changing the database name. Make sure that there are no open connections to the database. In Object Explorer, connect to an instance of SQL Server, and then expand that instance. Or on the top menu, select View, and then select Object Explorer: In SQL Server Management Studio, select Object Explorer. Use the following steps to rename a SQL Server or Azure SQL database using SQL Server Management Studio. Requires ALTER permission on the database. It's not possible to rename an Azure SQL database configured in an active geo-replication relationship.For more information, see Database Files and Filegroups. Renaming a database does not change the physical name of the database files on disk, or the logical names of the files.In Azure SQL Database, you must make sure no other users have an open connection to the database to be renamed.For more information, see set the database to single-user mode. In SQL Server, you can set a database in single user mode to close any open connections.For more information, see Open Activity Monitor in SQL Server Management Studio (SSMS). Use SQL Server Management Studio Activity Monitor to find other connections to the database, and close them.The database name cannot be changed while other users are accessing the database.To rename a database in Azure Synapse Analytics or Parallel Data Warehouse, use the RENAME (Transact-SQL) statement.
0 Comments
Leave a Reply. |