[sql] SQL Query for Logins

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

Thank you. More than one of you had the answer I was looking for:

SELECT * FROM syslogins 

This question is related to sql sql-server

The answer is


Is this what you're after?

select * from master.syslogins

Starting with SQL 2008, you should use sys.server_principals instead of sys.syslogins, which has been deprecated.


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.


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


@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


On SQL Azure as of 2012;

logins:

SELECT * from master.sys.sql_logins

users:

SELECT * from master.sys.sysusers

Select * From Master..SysUsers Where IsSqlUser = 1

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


EXEC sp_helplogins

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

EXEC sp_helplogins @LoginNamePattern='fred'