for role information(sql 2005)
select * from sys.database_principals where [type] = 'R' or [type] = 'A'
R = database role
A = application role
Main Topics
Browse All TopicsHow to script out a list of all the usernames and roles for all databases in SQL 2000
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
CREATE PROCEDURE dbo.usp_GetDatabaseUserSec
AS
BEGIN
CREATE TABLE #DBTable (
DatabaseName VARCHAR (128) ,
LoginName VARCHAR(128) NULL ,
Role VARCHAR(40) NULL ,
DatabaseAccess VARCHAR (5) NULL ,
ValidLogin VARCHAR (5) NULL ,
WindowsUser VARCHAR (5) NULL ,
WindowsGroup VARCHAR (5) NULL ,
SQLServerLogin VARCHAR (5) NULL ,
AliasedLogin VARCHAR (5) NULL ,
ApplicationRole VARCHAR (5) NULL )
DECLARE dbcursor CURSOR
READ_ONLY
FOR
SELECT replace(name,' ','') as AliasName, name FROM master..sysdatabases
DECLARE @name VARCHAR(50)
DECLARE @aliasname VARCHAR(50)
OPEN dbcursor
FETCH NEXT FROM dbcursor INTO @aliasname,@name
WHILE (@@fetch_status <> -1)
BEGIN
INSERT INTO #DBTable(DatabaseName , LoginName , Role , DatabaseAccess , ValidLogin , WindowsUser , WindowsGroup ,
SQLServerLogin , AliasedLogin , ApplicationRole )
EXEC(
'USE [' + @name + ']
SELECT
''' + @aliasname + ''' AS DatabaseName,su.name AS LoginName, su2.name AS Role,
CASE WHEN su.hasdbaccess = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS DatabaseAccess,
CASE WHEN su.islogin = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS ValidLogin,
CASE WHEN su.isntname = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS WindowsUser,
CASE WHEN su.isntgroup = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS WindowsGroup,
CASE WHEN su.issqluser = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS SQLServerLogin,
CASE WHEN su.isaliased = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS AliasedLogin,
CASE WHEN su.isapprole = 1 THEN ''TRUE'' ELSE ''FALSE'' END AS ApplicationRole
FROM
sysmembers sm1 join sysusers su on sm1.memberuid = su.uid
join sysusers su2 on sm1.groupuid = su2.uid
ORDER BY
sm1.groupuid ASC,su2.name DESC, su.name ASC'
)
FETCH NEXT FROM dbcursor INTO @aliasname,@name
END
CLOSE dbcursor
DEALLOCATE dbcursor
SELECT * FROM #DBTable
ORDER BY DatabaseName asc, Role DESC, LoginName desc
END
go
Business Accounts
Answer for Membership
by: BinuthPosted on 2008-08-28 at 22:33:04ID: 22342723
you can access all login inforamtion from "sys.syslogins"(not sure sam in sql 2000 , im using sql 2005 here)
select * from sys.syslogins