User object level permissions at database in Azure SQL Database.

Select the database name from dropdown as USE command does not work in Azure SQL Databse.
SELECT DISTINCT pr.principal_id, pr.name AS [UserName], pr.type_desc AS [User_or_Role], pr.authentication_type_desc AS [Auth_Type], pe.state_desc,
  pe.permission_name, pe.class_desc, o.[name] AS 'Object'
  FROM sys.database_principals AS pr
  JOIN sys.database_permissions AS pe ON pe.grantee_principal_id = pr.principal_id
  LEFT JOIN sys.objects AS o on (o.object_id = pe.major_id)
Which user belong to which database role
go
SELECT ServerName=@@servername,dbname=db_name(),DP1.name AS DatabaseRoleName,   
    isnull (DP2.name, 'No members') AS DatabaseUserName   
FROM sys.database_role_members AS DRM  
RIGHT OUTER JOIN sys.database_principals AS DP1  
    ON DRM.role_principal_id = DP1.principal_id  
LEFT OUTER JOIN sys.database_principals AS DP2  
    ON DRM.member_principal_id = DP2.principal_id  
WHERE DP1.type = 'R' 
ORDER BY DP1.name; 

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server