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;
精彩评论