Sunday, March 27, 2011

SQL Query for Logins

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
From stackoverflow
  • EXEC sp_helplogins
    

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

    EXEC sp_helplogins @LoginNamePattern='fred'
    
  • Select * From Master..SysUsers Where IsSqlUser = 1
    
  • @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

  • 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.

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

  • Is this what you're after?

    select * from master..syslogins
    
  • -- 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

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

0 comments:

Post a Comment