Here’s a quick script to set a database to single user and then back to multi user.
You’ll need to do this when altering the database in situations like database name changes, file name changes or even restores
/* Set Database to Single User */ USE [master]; GO ALTER DATABASE [my_db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO /* Set Database to back to Multi User */ USE MASTER; ALTER DATABASE [my_db] SET MULTI_USER WITH ROLLBACK IMMEDIATE; GO