SQL Queries - Users
SQL Queries - Users
SQL Queries - Users
List of all SQL Server users
select distinct LOGINNAME
from dbo.SYSUSERS u, master.dbo.SYSLOGINS
where U.NAME = USER
List of Users with Database Access
select distinct
LOGINNAME = (case when (O.SID = 0x00) then NULL else L.LOGINNAME end),
user_name(O.GID),
O.UID,
O.HASDBACCESS
from dbo.SYSUSERS O
left join (select SID, LOGINNAME, 1 as MATCHED from MASTER.dbo.SYSLOGINS) L on L.SID = O.SID
where ((O.ISSQLROLE != 1
and O.ISAPPROLE != 1
and O.STATUS != 0
and MATCHED is not null)
or (O.SID = 0x00)
and O.HASDBACCESS = 1)
and O.ISALIASED != 1
order by O.LOGINNAME