如何在SQL脚本中测试SQL Server数据库是否处于单用户模式?
答案 0 :(得分:33)
您可以查看sys.databases
视图...
if (SELECT user_access_desc FROM sys.databases WHERE name = 'YourDb')
= 'SINGLE_USER'
begin
print 'It is in single user mode!'
end
答案 1 :(得分:0)
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;