Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check access in database

Status
Not open for further replies.

peac3

Technical User
Joined
Jan 17, 2009
Messages
226
Location
AU
Hi guys,
is there any other way to know whether we have access to this database other than via security -> users?

I have access to this database but I couldn't see my name in that list,
but I have checked via sysusers, I can see my name in there.

Thanks guys
 
This is for SQL 2005 and will show you what roles you are in:

Code:
DECLARE @username NVARCHAR(128); 
SET @username = 'YOURLOGIN';  
WITH CTE_Roles (role_principal_id) 
AS 
    ( 
    SELECT role_principal_id 
        FROM sys.database_role_members 
     --   WHERE member_principal_id = USER_ID(@username) 
        UNION ALL 
    SELECT drm.role_principal_id 
        FROM sys.database_role_members drm 
                INNER JOIN CTE_Roles CR 
                ON drm.member_principal_id = CR.role_principal_id 
    ) 
SELECT DISTINCT USER_NAME(role_principal_id) RoleName 
    FROM CTE_Roles 
    UNION ALL 
SELECT 'public' 
    ORDER BY RoleName;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top