SQL Query for Logins

SqlSql Server

Sql Problem Overview


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 

Sql Solutions


Solution 1 - Sql

Is this what you're after?

select * from master.syslogins

Solution 2 - Sql

On SQL Azure as of 2012;

logins:

SELECT * from master.sys.sql_logins

users:

SELECT * from master.sys.sysusers

Solution 3 - Sql

EXEC sp_helplogins

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

EXEC sp_helplogins @LoginNamePattern='fred'

Solution 4 - Sql

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

Solution 5 - Sql

@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

Solution 6 - Sql

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

Solution 7 - Sql

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

Solution 8 - Sql

Select * From Master..SysUsers Where IsSqlUser = 1

Solution 9 - Sql

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJimView Question on Stackoverflow
Solution 1 - SqlBrad WilsonView Answer on Stackoverflow
Solution 2 - SqlDeepSpace101View Answer on Stackoverflow
Solution 3 - SqlMatt HamiltonView Answer on Stackoverflow
Solution 4 - SqlBradCView Answer on Stackoverflow
Solution 5 - SqlakuView Answer on Stackoverflow
Solution 6 - SqlMatt HamiltonView Answer on Stackoverflow
Solution 7 - SqlPaul StoklosaView Answer on Stackoverflow
Solution 8 - SqlGateKillerView Answer on Stackoverflow
Solution 9 - SqlJasonView Answer on Stackoverflow