USE master GO ALTER DATABASE $(DBNAME)Pre20 SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO sp_Detach_db $(DBNAME)Pre20, FALSE, TRUE GO