Rename a Database in SQL Server

Spread the love

Introduction

We can rename a user-defined database in SQL Server by using SQL Server Management Studio or Transact-SQL. System databases cannot be renamed. The database name cannot be changed while it is online and other users are accessing the database. We can set a database in single-user mode to close any open connections.

Set the database to single-user mode

By TSQL

By SSMS

Right-click on Database > Properties

Option > Other options > Restrict access > SINGLE_USER

Rename SQL Server database using T-SQL

This command is useful for SQL server 2005, 2008, 2008R2, 2012 and onward

Or

By SSMS

Set the database to multi-user mode

By TSQL

By SSMS

Right-click on Database > Properties > Option > Other options > Restrict access > MULTI_USER


Spread the love
Author: OTi
Meet OTi, the brains behind the popular tech blog "OurTechIdeas.com." OTi is an accomplished author, tech enthusiast, and an expert in SQL Server. With over a decade of experience in the tech industry, he has become a trusted voice in the world of database management. OTi's passion for technology began at a young age, and he has been tinkering with computers ever since. He graduated with a degree in Computer Science and has since worked for some of the biggest tech companies in the world. His experience has given him a deep understanding of how technology works and how it can be used to improve our lives.

Leave a Reply

Your email address will not be published. Required fields are marked *