USE master
GO
DECLARE @DbName nvarchar(MAX)
SET @DbName = N'DataBase'
ALTER DATABASE @DbName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE @DbName SET OFFLINE WITH NO_WAIT
GO
ALTER DATABASE @DbName SET ONLINE
GO
ALTER DATABASE @DbName
SET MULTI_USER
GO
我知道我可以使用 EXEC,但它有点难看....