I'm looking for an answer but I can't find it. Just a lot of long scripts.
I need to list Login | Role (sysadmin
, dbcreator
, etc ) but I can't find a table to join.
I have this for now:
SELECT
name AS Login_Name, type_desc AS Account_Type
FROM
sys.server_principals
WHERE
TYPE IN ('U', 'S', 'G')
AND name NOT LIKE '%##%'
ORDER BY
name, type_desc
I need another column with the role.
With table should I search for it?
Thanks.
EDIT:
I see that sys.syslogins
has some information with binary.
Is it possible to use a CASE here? ( Programming is not my best )
Best Answer
No, don't use
sys.syslogins
- this is a deprecated compatibility view that is only there so people have time to change their existing code based on SQL Server 2000. Also, I'm completely unclear how you think aCASE
expression will help you. You need to join tosys.server_role_members
to find out which logins belong to which roles, and then back tosys.server_principals
again to get the name of each role.(I'm not sure what value you expect from the second
ORDER BY
column here.)If you want only a single row per login: