-- Abfrage der Objektberechtigungen des Benutzers
exec sp_helprotect NULL, 'Benutzername'
-- Abfrage der Rolle des Benutzers
exec sp_helpuser 'Benutzername'
-- Abfrage, welche Benutzer eine bestimmte Systemrolle haben
Exec sp_helpsrvrolemember 'Systemadministrator'
-- Verschachtelte Rollen können abgefragt werden
MIT tree_roles als
(
WÄHLE role_principal_id AUS, member_principal_id
VON sys.database_role_members
WOBEI member_principal_id = USER_ID('Benutzername')
UNION ALLE
WÄHLE c.role_principal_id,c.member_principal_id
VON sys.database_role_members als c
Innere Verbindung tree_roles
auf tree_roles.member_principal_id = c.role_principal_id
)
SELECT unterschiedliche USER_NAME(role_principal_id) RollenName
VON tree_roles
-- Basistabelle im Zusammenhang mit anderen Berechtigungen
Wählen Sie * aus sysusers aus
Wähle * aus Syspermissions aus
-- Wer hat Zugriff auf meine SQL-Server-Instanz?
AUSWÄHLEN
Name als UserName, type_desc als UserType, is_disabled als IsDisabled
VON sys.server_principals
wo type_desc in('WINDOWS_LOGIN', 'SQL_LOGIN')
geordnet nach UserType, Name, IsDisabled
-- Wer hat Zugriff auf meine Datenbanken?
AUSWÄHLEN
dp.name als Benutzername, dp.type_desc als Benutzertyp, sp.name als LoginName, sp.type_desc als LoginType als LoginType
VON sys.database_principals DP
TRITT sys.server_principals SP BEI dp.principal_id = sp.principal_id BEI
Reihenfolge nach UserType
Wählen Sie * aus sys.database_principals
-- Serverrollen
auswählen
p.name als BenutzerName, p.type_desc als UserType, pp.name als ServerRoleName, pp.type_desc als ServerRoleType
Aus sys.server_role_members Rollen
Tritt sys.server_principals p bei roles.member_principal_id = p.principal_id bei
Tritt sys.server_principals PP bei roles.role_principal_id = pp.principal_id
wobei pp.name in('sysadmin')
Ordnung nach ServerRoleName, BenutzerName
-- Datenbankrollen
AUSWÄHLEN
p.name als Benutzername, p.type_desc als Benutzertyp, pp.name als DBRoleName, pp.type_desc als DBRoleType pp.is_fixed_role als IfFixedRole
FROM sys.database_role_members Rollen
TRITT sys.database_principals p BEI roles.member_principal_id = p.principal_id BEI
TRITT sys.database_principals PP AUF roles.role_principal_id = pp.principal_id BEI.
wo pp.name in('db_owner', 'db_datawriter')
-- Was können diese Nutzer tun?
AUSWÄHLEN
grantor.name als GrantorName, dp.state_desc als StateDesc, dp.class_desc als ClassDesc, dp.permission_name als PermissionName ,
OBJECT_NAME(major_id) als ObjectName, GranteeName = grantee.name
VON sys.database_permissions DP
TRETEN Sie sys.database_principals Förderempfänger bei dp.grantee_principal_id = grantee.principal_id
TRETEN Sie sys.database_principals Förderer bei dp.grantor_principal_id = grantor.principal_id bei.
wobei permission_name wie '%UPDATE%'