What is the SQL query to check whether particular SQL Login is Enable or Disable?
+3
A:
SELECT is_disabled FROM sys.server_principals WHERE name = @name;
Updated after OP question:
'guest' is not a login (server principal) is an user (database principal) so you need to look for it in sys.database_principals. Users cannot be enabled nor disabled, they simply exist or don't exist. guest is a special built-in user that maps all server principals that are not explicitly mapped to another user: that is server principals (logins) that have access to the database but do not have a database principal (user) with a matching SID will be mapped to 'guest'. Except members of sysadmin role which are always mapped to dbo.
Remus Rusanu
2010-06-29 06:13:27
Thank You Very Much
John
2010-06-29 06:37:16
A:
SELECT name, type_desc, is_disabled
FROM sys.server_principals
WHERE name = 'sa'
Replace 'sa' with your desired login.
Oliver
2010-06-29 06:17:10