开发者

How to test if SQL Server database is in Single User Mode

How can I test if the SQL Server database is in Single User 开发者_如何学GoMode in a SQL script?


You can check the sys.databases view ...

if (SELECT user_access_desc FROM sys.databases WHERE name = 'YourDb') 
                                                            = 'SINGLE_USER'
    begin
       print 'It is in single user mode!'
    end


SELECT CASE WHEN (SELECT 1 FROM sys.databases 
                  WHERE name = 'YourDb' AND user_access_desc = 'SINGLE_USER') = 1 THEN 1 
                  ELSE 0 END AS SingleUserMode;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜