Login listing

  • Hey guys

    Help me its damm urgent

    I need to Get the list of logins and the respective username in the databases in sql server 2005

    the result should be

    Login_name,Database_name,User_name

    Thanks a lot in advance

  • What have you tried so far? Lookup database_principals and server_principals in books online.

    Jeffrey Williams
    Problems are opportunities brilliantly disguised as insurmountable obstacles.

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thank you for your efforts

    some how i figured it

    Here is the query

    Declare @login table ( Database_name Varchar(1000),Login_Name varchar(2000),Username varchar(200))

    Insert into @login

    exec sp_msforeachdb @command1= 'USE [?]; select db_name(), ss.name ,dp.name from sys.syslogins ss left join sys.database_principals dp on ss.sid = dp.sid where dp.type not like ''R'''

    Select * from @login where Database_name not in ( 'master','model','msdb','tempdb')

    thank you again

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply