tags:

views:

1251

answers:

8

What is the SQL query to select all of the MSSQL Server's logins?

Thanks, more then one of you had the answer I was looking for

SELECT * FROM syslogins
+3  A: 
EXEC sp_helplogins

You can also pass an "@LoginNamePattern" parameter to get information about a specific login:

EXEC sp_helplogins @LoginNamePattern='fred'
Matt Hamilton
+1  A: 
Select * From Master..SysUsers Where IsSqlUser = 1
GateKiller
+1  A: 

@allain, @GateKiller your query selects users not logins
To select logins you can use this query:

SELECT name FROM master..sysxlogins WHERE sid IS NOT NULL

In MSSQL2005/2008 syslogins table is used insted of sysxlogins

aku
A: 

Have a look in the syslogins or sysusers tables in the master schema. Not sure if this still still around in more recent MSSQL versions though. In MSSQL 2005 there are views called sys.syslogins and sys.sysusers.

Jason
+1  A: 

Selecting from sysusers will get you information about users on the selected database, not logins on the server.

Matt Hamilton
+1  A: 

Is this what you're after?

select * from master..syslogins
Brad Wilson
A: 

-- Este Query te muestra los Roles que tiene cada Login

USE MASTER SELECT DISTINCT SYSL.LOGINNAME, SYSL.DBNAME AS DEFAULTDB, SYSL.SECURITYADMIN, SYSL.SERVERADMIN, SYSL.SETUPADMIN, SYSL.PROCESSADMIN, SYSL.DISKADMIN, SYSL.DBCREATOR, SYSL.BULKADMIN FROM SYSLOGINS AS SYSL INNER JOIN SYSXLOGINS AS SYSX ON SYSL.SID = SYSX.SID ORDER BY SYSL.LOGINNAME

-- Este Stored Procedure Te muestra la Información de cada Login

-- y las bases de datos a las que tiene acceso

Exec SP_helpLogins

A: 

sp_helplogins will give you the logins along with the DBs and the rights on them.